Opened 3 years ago

Closed 3 years ago

Last modified 3 years 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 Rev(s):
Wiki Page:


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

    Kind variable also used as type variable: ‘a_asJA’
    In the declaration for class C_asJy

    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 3 years 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 [])  


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 3 years ago by goldfire

Confirmed reproducible in HEAD.

comment:3 Changed 3 years ago by goldfire

Resolution: duplicate
Status: newclosed

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

comment:4 Changed 3 years ago by simonpj

Test Case: th/T9081

I'll add it as a regression test though.


comment:5 Changed 3 years ago by Simon Peyton Jones <simonpj@…>

Note: See TracTickets for help on using tickets.