Opened 13 months ago

Closed 7 months ago

Last modified 7 months ago

#9081 closed bug (duplicate)

Template Haskell gets confused with scoped kind variables in a class declaration

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

Description

When I say

{-# LANGUAGE TemplateHaskell, DataKinds, PolyKinds, TypeFamilies #-}

module Bug where

import Data.Proxy

$( [d|
  class kproxy ~ 'KProxy => C (kproxy :: KProxy a) where
    type TF (x :: a) :: Bool
  |])

I get

/Users/rae/temp/Bug.hs:7:4:
    Kind variable also used as type variable: ‘a_asJA’
    In the declaration for class C_asJy

/Users/rae/temp/Bug.hs:7:4:
    The exact Name ‘kproxy_asJB’ is not in scope
      Probable cause: you used a unique Template Haskell name (NameU), 
      perhaps via newName, but did not bind it
      If that's it, then -ddump-splices might be useful

The code in the TH quote compiles fine on its own.

Change History (5)

comment:1 Changed 13 months ago by goldfire

This problem came up in a slightly different context. Compiling this module

{-# LANGUAGE TemplateHaskell, TypeFamilies, PolyKinds #-}

module A where

import Language.Haskell.TH

$( do a <- newName "a"
      k <- newName "k"
      b <- newName "b"
      return [ ClassD [] (mkName "C") [KindedTV a (VarT k)] []
               [ FamilyD TypeFam (mkName "TF") [KindedTV b (VarT k)] Nothing ] ] )

$(do infoC  <- reify ''C
     infoTF <- reify ''TF
     runIO $ do
       putStrLn (show infoC)
       putStrLn (show infoTF)
     return [])  

produces

ClassI (ClassD [] A.C [KindedTV a_1627506463 (VarT k_1627506468)] [] []) []
FamilyI (FamilyD TypeFam A.TF [KindedTV b_1627506465 (VarT k_1627506464)] (Just StarT)) []

Note that the uniques in the k variables in the output are different.

It's possible that these are two separate bugs, but my hunch is that they are the same.

comment:2 Changed 13 months ago by goldfire

Confirmed reproducible in HEAD.

comment:3 Changed 7 months ago by goldfire

  • Resolution set to duplicate
  • Status changed from new to closed

Not reproducible anymore, in HEAD or in 7.8.3. I guess it's fixed now.

comment:4 Changed 7 months ago by simonpj

  • Test Case set to th/T9081

I'll add it as a regression test though.

Simon

comment:5 Changed 7 months ago by Simon Peyton Jones <simonpj@…>

Note: See TracTickets for help on using tickets.