#12615 closed bug (fixed)

Record pattern synonyms cause spurious name shadowing warnings

Reported by: gelisam Owned by: mpickering
Priority: normal Milestone: 8.0.2
Component: Compiler Version: 8.0.1
Keywords: PatternSynonyms Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case: patsyn/should_compile/T12615
Blocked By: Blocking:
Related Tickets: Differential Rev(s): Phab:D2545
Wiki Page:

Description

The example given in the documentation gives a warning when compiled with -Wall:

{-# LANGUAGE PatternSynonyms #-}
{-# OPTIONS_GHC -Wall #-}
module Test where

-- Test.hs:13:24: warning: [-Wname-shadowing]
--     This binding for ‘x’ shadows the existing binding
--       defined at Test.hs:13:15
-- 
-- Test.hs:13:27: warning: [-Wname-shadowing]
--     This binding for ‘y’ shadows the existing binding
--       defined at Test.hs:13:18
pattern Point :: Int -> Int -> (Int, Int)
pattern Point{x, y} = (x, y)

I don't see anything being shadowed here, so I don't think GHC should produce these warnings.

Also, the type signature for that example in the documentation is pattern Point :: (Int, Int), which doesn't compile. Should I file a separate bug for that?

Change History (6)

comment:1 Changed 11 months ago by mpickering

Keywords: PatternSynonyms added
Owner: set to mpickering

I will take care of both points mentioned in the ticket.

comment:2 Changed 11 months ago by mpickering

This isn't actually a problem with record pattern synonyms per se but something that is exposed by them.

You can also trigger the problem with

{-# LANGUAGE NoImplicitPrelude, PatternSynonyms #-}
{-# OPTIONS_GHC -Wall #-}
module Test where

x = ()

pattern Point2 :: () -> () -> ((), ())
pattern Point2 x y = (x, y)

This is because the way checking for shadowed names works assumes that all patterns are introducing binders. Clearly in the case of pattern synonyms this assumption fails so we need to refine this check.

comment:3 Changed 11 months ago by mpickering

Differential Rev(s): Phab:D2545
Status: newpatch
Test Case: patsyn/should_compile/T12615

comment:4 Changed 11 months ago by Ben Gamari <ben@…>

In 1851349a/ghc:

Don't warn about name shadowing when renaming the patten in a PatSyn decl

Previously the renamer assumed that *any* time we renamed a pattern, the
pattern was introducing new binders. This isn't true in pattern synonym
declarations where the pattern is used as part of a definition.

We add a special case to not warn in this situation.

Reviewers: simonpj, austin, bgamari

Reviewed By: simonpj

Subscribers: simonpj, thomie

Differential Revision: https://phabricator.haskell.org/D2545

GHC Trac Issues: #12615

comment:5 Changed 11 months ago by bgamari

Milestone: 8.0.2
Status: patchmerge

comment:6 Changed 10 months ago by bgamari

Resolution: fixed
Status: mergeclosed
Note: See TracTickets for help on using tickets.