e70c5db7b14beb55437c59ab8cccb5faf2f20a4f
[ghc.git] / testsuite / tests / overloadedrecflds / should_run / overloadedrecfldsrun04.hs
1 -- Test that DuplicateRecordFields works with TemplateHaskell
2
3 {-# LANGUAGE DuplicateRecordFields, TemplateHaskell #-}
4
5 import Language.Haskell.TH
6 import Language.Haskell.TH.Syntax
7
8 -- Splice in a datatype with field...
9 $(return [DataD [] (mkName "R") [] [RecC (mkName "MkR") [(mkName "foo", NotStrict, ConT ''Int)]] []])
10
11 -- New TH story means reify only sees R if we do this:
12 $(return [])
13
14 -- ... and check that we can inspect it
15 main = do putStrLn $(do { info <- reify ''R
16 ; case info of
17 TyConI (DataD _ _ _ [RecC _ [(n, _, _)]] _) ->
18 do { info' <- reify n
19 ; lift (pprint info ++ "\n" ++ pprint info')
20 }
21 _ -> error "unexpected result of reify"
22 })
23 putStrLn $(do { info <- reify 'foo
24 ; case info of
25 VarI n _ _ ->
26 do { info' <- reify n
27 ; lift (pprint info ++ "\n" ++ pprint info')
28 }
29 })
30 print (foo (MkR { foo = 42 }))