[GHC] #14630: name shadowing warnings by record pattern synonyms + RecordWildCards or NamedFieldPuns

GHC ghc-devs at haskell.org
Thu Jan 4 02:15:47 UTC 2018


#14630: name shadowing warnings by record pattern synonyms + RecordWildCards or
NamedFieldPuns
-------------------------------------+-------------------------------------
        Reporter:  mizunashi_mana    |                Owner:  (none)
            Type:  bug               |               Status:  new
        Priority:  normal            |            Milestone:
       Component:  Compiler          |              Version:  8.2.2
      Resolution:                    |             Keywords:
                                     |  PatternSynonyms
Operating System:  Unknown/Multiple  |         Architecture:
 Type of failure:  Incorrect         |  Unknown/Multiple
  error/warning at compile-time      |            Test Case:
      Blocked By:                    |             Blocking:
 Related Tickets:                    |  Differential Rev(s):
       Wiki Page:                    |
-------------------------------------+-------------------------------------

Comment (by RyanGlScott):

 Hrm, I'm not sure how to fix this. The issues lies with the
 `is_shadowed_gre` function in `RnUtils`, defined
 [http://git.haskell.org/ghc.git/blob/7a25659efc4d22086a9e75dc90e3701c1706c625:/compiler/rename/RnUtils.hs#l163
 here]:

 {{{#!hs
 is_shadowed_gre :: GlobalRdrElt -> RnM Bool
     -- Returns False for record selectors that are shadowed, when
     -- punning or wild-cards are on (cf Trac #2723)
 is_shadowed_gre gre | isRecFldGRE gre
     = do { dflags <- getDynFlags
          ; return $ not (xopt LangExt.RecordPuns dflags
                          || xopt LangExt.RecordWildCards dflags) }
 is_shadowed_gre _other = return True
 }}}

 This uses the `isRecFldGRE` function to detect record selectors, which is
 in turn defined
 [http://git.haskell.org/ghc.git/blob/649e777211fe08432900093002547d7358f92d82:/compiler/basicTypes/RdrName.hs#l846
 as follows]:

 {{{#!hs
 isRecFldGRE :: GlobalRdrElt -> Bool
 isRecFldGRE (GRE {gre_par = FldParent{}}) = True
 isRecFldGRE _                             = False
 }}}

 The problem is that pattern synonym record selectors don't use `FldParent`
 as their `Parent`, but rather `NoParent`. At first, I thought this might
 have been an oversight, but it turns out there's a reason for this, as
 explained in
 [http://git.haskell.org/ghc.git/blob/649e777211fe08432900093002547d7358f92d82:/compiler/basicTypes/RdrName.hs#l578
 this comment]:

 > Record pattern synonym selectors are treated differently. Their parent
 information is `NoParent` in the module in which they are defined. This is
 because a pattern synonym `P` has no parent constructor either.

 So it seems that we need to adjust `isRecFldGRE` to be aware of this fact
 somehow. But I doubt that having `isRecFldGRE` return `True` whenever it
 sees //any// occurrence of `NoParent` is the right thing to do... any
 ideas?

-- 
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/14630#comment:2>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler


More information about the ghc-tickets mailing list