Fix #11287.
[ghc.git] / testsuite / tests / th / TH_lookupName.hs
1 -- test 'lookupTypeName' and 'lookupValueName'
2
3 import Language.Haskell.TH
4
5 import qualified TH_lookupName_Lib
6 import qualified TH_lookupName_Lib as TheLib
7
8 f :: String
9 f = "TH_lookupName.f"
10
11 data D = D
12
13 $(return [])
14
15 main = mapM_ print [
16 -- looking up values
17 $(do { Just n <- lookupValueName "f" ; varE n }),
18 $(do { Nothing <- lookupTypeName "f"; [| "" |] }),
19 -- looking up types
20 $(do { Just n <- lookupTypeName "String"; sigE [| "" |] (conT n) }),
21 $(do { Nothing <- lookupValueName "String"; [| "" |] }),
22 -- namespacing
23 $(do { Just n <- lookupValueName "D"; DataConI{} <- reify n; [| "" |] }),
24 $(do { Just n <- lookupTypeName "D"; TyConI{} <- reify n; [| "" |] }),
25 -- qualified lookup
26 $(do { Just n <- lookupValueName "TH_lookupName_Lib.f"; varE n }),
27 $(do { Just n <- lookupValueName "TheLib.f"; varE n }),
28 -- shadowing
29 $(TheLib.lookup_f),
30 $( [| let f = "local f" in $(TheLib.lookup_f) |] ),
31 $( [| let f = "local f" in $(do { Just n <- lookupValueName "f"; varE n }) |] ),
32 $( [| let f = "local f" in $(varE 'f) |] ),
33 let f = "local f" in $(TheLib.lookup_f),
34 let f = "local f" in $(varE 'f)
35 ]