Skip to content

Declarations processed in unexpected order in the presence of TH declaration splices

In ghc-7.8 reify returns only first data type that have an instance, here is a code:

Test.hs

{-# LANGUAGE TemplateHaskell #-}
module Test where

import Language.Haskell.TH

class C a

inner :: ExpQ
inner = do
  ClassI _ instances <- reify ''C
  let sh = show instances
  [| sh |]

def :: String -> DecsQ
def x =
  let dn = mkName x
  in do dt <- dataD (cxt []) dn [] [] [] 
        i <- instanceD (cxt []) (appT (conT ''C) (conT dn)) [] -- [d| instance C $(cn) |]
        return [dt,i]

test :: ExpQ
test = [| print $inner |]

test.hs

{-# LANGUAGE TemplateHaskell #-}

import Test

def "A"
def "B"

main = $(test)

running test returns:

"[InstanceD [] (AppT (ConT Test.C) (ConT Main.A)) []]"

under 7.6 test returns:

"[InstanceD [] (AppT (ConT Test.C) (ContT Main.B) [], InstanceD [] (AppT (ConT Test.C) (ConT Main.A) []]"

Trac metadata
Trac field Value
Version 7.8.3
Type Bug
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component Compiler
Test case
Differential revisions
BlockedBy
Related
Blocking
CC
Operating system
Architecture
Edited by Richard Eisenberg
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information