[GHC] #11098: TH mishandles type variables that begin with an underscore

GHC ghc-devs at haskell.org
Tue Nov 17 10:16:48 UTC 2015


#11098: TH mishandles type variables that begin with an underscore
-------------------------------------+-------------------------------------
        Reporter:  goldfire          |                Owner:  jstolarek
            Type:  bug               |               Status:  new
        Priority:  normal            |            Milestone:  8.0.1
       Component:  Template Haskell  |              Version:  7.10.2
      Resolution:                    |             Keywords:
Operating System:  Unknown/Multiple  |         Architecture:
                                     |  Unknown/Multiple
 Type of failure:  None/Unknown      |            Test Case:
      Blocked By:                    |             Blocking:
 Related Tickets:                    |  Differential Rev(s):
       Wiki Page:                    |
-------------------------------------+-------------------------------------

Comment (by jstolarek):

 The problem arises in the parser, where we assume that when named wild
 cards are enabled then any type variables that starts with an underscore
 is a wild card:

 {{{
 | tyvar  {% do { nwc <- namedWildCardsEnabled -- (See Note [Unit tuples])
                ; let tv@(Unqual name) = unLoc $1
                ; return $ if (startsWithUnderscore name && nwc)
                           then (sL1 $1 (mkNamedWildCardTy tv))
                           else (sL1 $1 (HsTyVar tv)) } }
 }}}

 My idea for the solution is to unconditionally create an `HsTyVar` in the
 parser and then be smart during renaming:

 {{{#!hs
 rnHsTyKi isType doc (HsTyVar rdr_name)
   = do { dflags <- getDynFlags
        ; let is_wild_card_name  = startsWithUnderscore (rdrNameOcc
 rdr_name)
              wild_cards_enabled = xopt Opt_NamedWildCards dflags
        ; is_in_scope <- isJust `fmap` lookupOccRn_maybe rdr_name
        ; if is_wild_card_name && not is_in_scope && wild_cards_enabled
          then rnHsTyKi isType doc (HsWildCardTy (NamedWildCard rdr_name))
          else do { name <- rnTyVar isType rdr_name
                  ; return (HsTyVar name, unitFV name) }
        }
 }}}

 That however does not work - the names of variables seem to be in scope
 even when they were not explicitly declared using a `forall`. So the
 question is: how do I detect if a variable was introduced using a
 `forall`?

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


More information about the ghc-tickets mailing list