summaryrefslogtreecommitdiff
path: root/testsuite/tests/th/T11680.hs
blob: 6675393c0cadacefcdec229b3afe01eac642e4d1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE DuplicateRecordFields #-}


module T11680 where


import qualified Data.List                  as List
import           Language.Haskell.TH.Syntax         (addTopDecls)


------------------------------------------------------------------------------
-- # No suggestions or exact match
ex1 :: Bool
ex1 = noMatches

------------------------------------------------------------------------------
-- # One suggestion (abcd), but no exact match
ex2 :: [a]
ex2 = abce

abcd :: String
abcd = "abcd"

------------------------------------------------------------------------------
-- # No suggestions, but an exact match after a splice
-- # Exact match following a single-line splice
-- # One splice separating use and binding
-- # Annotation does not affect identification of top-level splice
ex3 :: Int
ex3 = foo

------------------------------------------------------------------------------
-- # Suggestions (bat, baz) and an exact match after a splice
-- # Out-of-scope suggestion (bad) NOT reported
-- # Exact match following a multi-line splice
-- # Multiple splices separating use and binding
ex4 :: ()
ex4 = bar

bat :: [Double]
bat = [1.2, 3.4]

baz :: Bool
baz = True

------------------------------------------------------------------------------
-- # No suggestions, but an exact match IN a splice
ex5 :: [Double]
ex5 = ns

------------------------------------------------------------------------------
-- # Qualified suggestion and an exact local match after a splice
-- # Inline bracket does not affect identification of top-level splice
ex6 = intercalate

------------------------------------------------------------------------------
-- # Qualified suggestion, but no exact local match
ex7 = nub

------------------------------------------------------------------------------
-- # No suggestions or matches for an out-of-scope duplicate field selector
ex8 :: Int
ex8 = x undefined

------------------------------------------------------------------------------
-- # Exact match to binding added by addTopDecls in next inter-splice group
ex9 :: ()
ex9 = cat

----------------------------------------------------------------------------
-- END OF INTER-SPLICE GROUP
----------------------------------------------------------------------------

------------------------------------------------------------------------------
-- # In a splice, suggestions for out-of-scope variable (cab) dependent upon
-- #   whether that variable is used in a binding added by addTopDecls:
-- #   cat and cap both suggested for f's cab, only cap suggested for g's cab
$(do
    ds <- [d| f = cab
              cat = ()
            |]
    addTopDecls ds
    [d| g = cab
        cap = True
      |])

------------------------------------------------------------------------------
-- # Exact match to binding added by addTopDecls in current inter-splice group
ex10 :: ()
ex10 = cat

----------------------------------------------------------------------------
-- END OF INTER-SPLICE GROUP
----------------------------------------------------------------------------
$(return [])

{-# ANN foo (Just "hello") #-}
foo :: Int
foo = 23


----------------------------------------------------------------------------
-- END OF INTER-SPLICE GROUP
----------------------------------------------------------------------------
[d| ms = 3 : ns :: [Int]
    ns = 4 : ms
  |]

bar = [| 23.6 : bat |]

bad = False

intercalate = undefined

data D = D { x :: Int
           , y :: Double
           }

data E = E { x :: Bool
           , y :: String
           }