TH: Type family instances inside InstanceD are rejected
The following code is broken by f92591de:
$ cat TH.hs
{-# LANGUAGE UnicodeSyntax #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeFamilies #-}
module TH where
import Language.Haskell.TH
class C α where
type AT α ∷ ★
bang ∷ DecsQ
bang = return [InstanceD [] (AppT (ConT ''C) (ConT ''Int))
[TySynInstD ''AT [ConT ''Int] (ConT ''Int)]]
$ cat Main.hs
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeFamilies #-}
import TH
$(bang)
main = return ()
$ ghc-7.5.20120217 -fforce-recomp -ddump-splices TH.hs Main.hs
[1 of 2] Compiling TH ( TH.hs, TH.o )
[2 of 2] Compiling Main ( Main.hs, Main.o )
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
Loading package pretty-1.1.1.0 ... linking ... done.
Loading package array-0.3.0.3 ... linking ... done.
Loading package deepseq-1.2.0.1 ... linking ... done.
Loading package containers-0.4.2.0 ... linking ... done.
Loading package template-haskell ... linking ... done.
Main.hs:6:3:
Illegal declaration(s) in an instance declaration:
type instance AT Int = Int
When splicing a TH declaration:
instance TH.C GHC.Types.Int
where type TH.AT GHC.Types.Int = GHC.Types.Int
I attached a patch that fixes the problem (at least for my library). Please review.
Trac metadata
Trac field | Value |
---|---|
Version | 7.5 |
Type | Bug |
TypeOfFailure | OtherFailure |
Priority | normal |
Resolution | Unresolved |
Component | Template Haskell |
Test case | |
Differential revisions | |
BlockedBy | |
Related | |
Blocking | |
CC | |
Operating system | |
Architecture |