Opened 6 months ago

Closed 6 months ago

#8499 closed bug (fixed)

Template Haskell: newName not new enough

Reported by: goldfire Owned by:
Priority: normal Milestone:
Component: Template Haskell Version: 7.7
Keywords: Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Difficulty: Unknown
Test Case: th/T8499 Blocked By:
Blocking: Related Tickets:


When I compile this:

{-# LANGUAGE TemplateHaskell, PolyKinds, DataKinds #-}
{-# OPTIONS_GHC -Wall #-}

import Language.Haskell.TH

$( do TyConI (DataD _ _ [PlainTV tvb_a] _ _) <- reify ''Maybe
      my_a <- newName "a"
      return [TySynD (mkName "SMaybe") [KindedTV my_a (AppT (ConT ''Maybe) (VarT tvb_a))]
              (TupleT 0)] )

I get this:

/Users/rae/temp/Bug.hs:6:4: Warning:
    This binding for ‛a’ shadows the existing binding
      bound at /Users/rae/temp/Bug.hs:6:4

The problem is that, in the library definition for Maybe, the name of its type variable is a. In my Template Haskell code, I read in Maybe's definition (using reify) to extract the name of Maybe's type variable. I then create a new name, also seeded with "a". Then, I create a type synonym definition

type SMaybe (a_newName :: Maybe a_Maybe) = ()

where a_newName is the variable I newNamed, and a_Maybe is the name I slurped from Maybe's definition. These variables print with different uniques, but the warning comes up anyway.

This problem actually came up in real code (singletons library), where I'm trying to get the generated code to be warning-free.

This was tested on 7.7.20131031.

Change History (3)

comment:1 Changed 6 months ago by Simon Peyton Jones <simonpj@…>

In e470290f87015043af7f297425a722329f726134/ghc:

Fix checking of shadowed names (fixes Trac #8499)

comment:2 Changed 6 months ago by Simon Peyton Jones <simonpj@…>

comment:3 Changed 6 months ago by simonpj

  • Resolution set to fixed
  • Status changed from new to closed
  • Test Case set to th/T8499
Note: See TracTickets for help on using tickets.