summaryrefslogtreecommitdiff
path: root/testsuite/tests/th
diff options
context:
space:
mode:
authorRichard Eisenberg <rae@richarde.dev>2019-09-26 14:31:30 +0100
committerMarge Bot <ben+marge-bot@smart-cactus.org>2019-10-08 13:26:20 -0400
commit9612e91c793830b3049d2bc9a9ee28d9d82b928d (patch)
treef34d5c1f295026aaf1e706b8e2d20426fad6ac23 /testsuite/tests/th
parentbf02c26402cf926d41c006ab930ed9747e92a373 (diff)
downloadhaskell-9612e91c793830b3049d2bc9a9ee28d9d82b928d.tar.gz
Solve constraints from top-level groups sooner
Previously, all constraints from all top-level groups (as separated by top-level splices) were lumped together and solved at the end. This could leak metavariables to TH, though, and that's bad. This patch solves each group's constraints before running the next group's splice. Naturally, we now report fewer errors in some cases. One nice benefit is that this also fixes #11680, but in a much simpler way than the original fix for that ticket. Admittedly, the error messages degrade just a bit from the fix from #11680 (previously, we informed users about variables that will be brought into scope below a top-level splice, and now we just report an out-of-scope error), but the amount of complexity required throughout GHC to get that error was just not worth it. This patch thus reverts much of f93c9517a2c6e158e4a5c5bc7a3d3f88cb4ed119. Fixes #16980 Test cases: th/T16980{,a}
Diffstat (limited to 'testsuite/tests/th')
-rw-r--r--testsuite/tests/th/T10267.stderr51
-rw-r--r--testsuite/tests/th/T11680.stderr31
-rw-r--r--testsuite/tests/th/T16980.hs16
-rw-r--r--testsuite/tests/th/T16980.stderr2
-rw-r--r--testsuite/tests/th/T16980a.hs10
-rw-r--r--testsuite/tests/th/T16980a.stderr5
-rw-r--r--testsuite/tests/th/T2222.stderr2
-rw-r--r--testsuite/tests/th/T5358.stderr30
-rw-r--r--testsuite/tests/th/all.T2
9 files changed, 71 insertions, 78 deletions
diff --git a/testsuite/tests/th/T10267.stderr b/testsuite/tests/th/T10267.stderr
index 71aca96b86..6262bf72ff 100644
--- a/testsuite/tests/th/T10267.stderr
+++ b/testsuite/tests/th/T10267.stderr
@@ -27,58 +27,7 @@ T10267.hs:8:1: error:
j :: forall a0. a0 -> a0
with j @a
(bound at T10267.hs:8:1)
- k :: forall a. a -> a
- with k @a
- (defined at T10267.hs:14:3)
- l :: forall a. a -> a
- with l @a
- (defined at T10267.hs:23:3)
- foo :: forall a. a -> a
- with foo @a
- (defined at T10267.hs:33:1)
id :: forall a. a -> a
with id @a
(imported from ‘Prelude’ at T10267.hs:3:8-13
(and originally defined in ‘GHC.Base’))
-
-T10267.hs:14:3: error:
- • Found hole: _foo :: a -> a
- Where: ‘a’ is a rigid type variable bound by
- the type signature for:
- k :: forall a. a -> a
- at T10267.hs:(14,3)-(21,2)
- Or perhaps ‘_foo’ is mis-spelled, or not in scope
- • In the expression: _foo
- In an equation for ‘k’: k = _foo
- • Relevant bindings include k :: a -> a (bound at T10267.hs:14:3)
- Valid hole fits include
- k :: a -> a (bound at T10267.hs:14:3)
- j :: forall a0. a0 -> a0
- with j @a
- (bound at T10267.hs:8:1)
- i :: forall a0. a0 -> a0
- with i @a
- (bound at T10267.hs:8:1)
- l :: forall a. a -> a
- with l @a
- (defined at T10267.hs:23:3)
- foo :: forall a. a -> a
- with foo @a
- (defined at T10267.hs:33:1)
- id :: forall a. a -> a
- with id @a
- (imported from ‘Prelude’ at T10267.hs:3:8-13
- (and originally defined in ‘GHC.Base’))
-
-T10267.hs:23:3: error:
- • Found hole: _ :: a
- Where: ‘a’ is a rigid type variable bound by
- the type signature for:
- l :: forall a. a -> a
- at T10267.hs:(23,3)-(30,2)
- • In the expression: _
- In an equation for ‘l’: l x = _
- • Relevant bindings include
- x :: a (bound at T10267.hs:23:3)
- l :: a -> a (bound at T10267.hs:23:3)
- Valid hole fits include x :: a (bound at T10267.hs:23:3)
diff --git a/testsuite/tests/th/T11680.stderr b/testsuite/tests/th/T11680.stderr
index 5788490f35..07d88403f1 100644
--- a/testsuite/tests/th/T11680.stderr
+++ b/testsuite/tests/th/T11680.stderr
@@ -5,25 +5,17 @@ T11680.hs:20:7: error:
• Variable not in scope: abce :: [a]
• Perhaps you meant ‘abcd’ (line 23)
-T11680.hs:31:7: error:
- • Variable not in scope: foo :: Int
- • ‘foo’ (line 100) is not in scope before the splice on line 96
+T11680.hs:31:7: error: Variable not in scope: foo :: Int
T11680.hs:39:7: error:
• Variable not in scope: bar :: ()
- • ‘bar’ (line 110) is not in scope
- before the splice on lines 106-108
- Perhaps you meant one of these: ‘bat’ (line 42), ‘baz’ (line 45)
+ • Perhaps you meant one of these: ‘bat’ (line 42), ‘baz’ (line 45)
-T11680.hs:50:7: error:
- • Variable not in scope: ns :: [Double]
- • ‘ns’ (splice on lines 106-108) is not in scope before line 106
+T11680.hs:50:7: error: Variable not in scope: ns :: [Double]
T11680.hs:55:7: error:
• Variable not in scope: intercalate
- • ‘intercalate’ (line 114) is not in scope
- before the splice on lines 106-108
- Perhaps you meant ‘List.intercalate’ (imported from Data.List)
+ • Perhaps you meant ‘List.intercalate’ (imported from Data.List)
T11680.hs:59:7: error:
• Variable not in scope: nub
@@ -33,17 +25,4 @@ T11680.hs:64:7: error: Variable not in scope: x :: t0 -> Int
T11680.hs:69:7: error:
• Variable not in scope: cat :: ()
- • ‘cat’ (splice on lines 79-86) is not in scope before line 79
- Perhaps you meant ‘bat’ (line 42)
-
-T11680.hs:79:3: error:
- • Variable not in scope: cab
- • Perhaps you meant ‘cap’ (line 79)
-
-T11680.hs:79:3: error:
- • Variable not in scope: cab
- • Perhaps you meant one of these: ‘cat’ (line 79), ‘cap’ (line 79)
-
-T11680.hs:91:8: error:
- • Variable not in scope: cat :: ()
- • Perhaps you meant one of these: ‘bat’ (line 42), ‘cap’ (line 79)
+ • Perhaps you meant ‘bat’ (line 42)
diff --git a/testsuite/tests/th/T16980.hs b/testsuite/tests/th/T16980.hs
new file mode 100644
index 0000000000..5acd455a07
--- /dev/null
+++ b/testsuite/tests/th/T16980.hs
@@ -0,0 +1,16 @@
+{-# LANGUAGE TemplateHaskell #-}
+
+module T16980 where
+
+import Language.Haskell.TH
+import Language.Haskell.TH.Ppr
+
+import System.IO
+
+aNumber = 5
+
+do VarI name1 t1 _ <- reify 'aNumber
+ runIO . print $ ppr_sig name1 t1
+ runIO . print =<< reifyType 'aNumber
+ runIO $ hFlush stdout
+ return []
diff --git a/testsuite/tests/th/T16980.stderr b/testsuite/tests/th/T16980.stderr
new file mode 100644
index 0000000000..b9d25b4aab
--- /dev/null
+++ b/testsuite/tests/th/T16980.stderr
@@ -0,0 +1,2 @@
+T16980.aNumber :: GHC.Integer.Type.Integer
+ConT GHC.Integer.Type.Integer
diff --git a/testsuite/tests/th/T16980a.hs b/testsuite/tests/th/T16980a.hs
new file mode 100644
index 0000000000..b3024c4a41
--- /dev/null
+++ b/testsuite/tests/th/T16980a.hs
@@ -0,0 +1,10 @@
+module T16980a where
+
+default (Integer) -- just to be really explicit
+
+x = 5 -- this should be an Integer
+
+$(return [])
+
+y :: Int
+y = x -- this should be a type error; types cannot communicate across splices
diff --git a/testsuite/tests/th/T16980a.stderr b/testsuite/tests/th/T16980a.stderr
new file mode 100644
index 0000000000..52673a8779
--- /dev/null
+++ b/testsuite/tests/th/T16980a.stderr
@@ -0,0 +1,5 @@
+
+T16980a.hs:10:5: error:
+ • Couldn't match expected type ‘Int’ with actual type ‘Integer’
+ • In the expression: x
+ In an equation for ‘y’: y = x
diff --git a/testsuite/tests/th/T2222.stderr b/testsuite/tests/th/T2222.stderr
index 3265a5e938..c65f7da665 100644
--- a/testsuite/tests/th/T2222.stderr
+++ b/testsuite/tests/th/T2222.stderr
@@ -1,4 +1,4 @@
-inside b: p_0
+inside b: GHC.Integer.Type.Integer
inside d: GHC.Types.Bool
type of c: GHC.Types.Bool
inside f: GHC.Types.Bool
diff --git a/testsuite/tests/th/T5358.stderr b/testsuite/tests/th/T5358.stderr
index 4bfc53a78e..cc1df54bed 100644
--- a/testsuite/tests/th/T5358.stderr
+++ b/testsuite/tests/th/T5358.stderr
@@ -1,4 +1,34 @@
+T5358.hs:7:1: error:
+ • Couldn't match expected type ‘Int’ with actual type ‘p1 -> p1’
+ • The equation(s) for ‘t1’ have one argument,
+ but its type ‘Int’ has none
+
+T5358.hs:8:1: error:
+ • Couldn't match expected type ‘Int’ with actual type ‘p0 -> p0’
+ • The equation(s) for ‘t2’ have one argument,
+ but its type ‘Int’ has none
+
+T5358.hs:10:13: error:
+ • Couldn't match expected type ‘t -> a0’ with actual type ‘Int’
+ • The function ‘t1’ is applied to one argument,
+ but its type ‘Int’ has none
+ In the first argument of ‘(==)’, namely ‘t1 x’
+ In the expression: t1 x == t2 x
+ • Relevant bindings include
+ x :: t (bound at T5358.hs:10:9)
+ prop_x1 :: t -> Bool (bound at T5358.hs:10:1)
+
+T5358.hs:10:21: error:
+ • Couldn't match expected type ‘t -> a0’ with actual type ‘Int’
+ • The function ‘t2’ is applied to one argument,
+ but its type ‘Int’ has none
+ In the second argument of ‘(==)’, namely ‘t2 x’
+ In the expression: t1 x == t2 x
+ • Relevant bindings include
+ x :: t (bound at T5358.hs:10:9)
+ prop_x1 :: t -> Bool (bound at T5358.hs:10:1)
+
T5358.hs:14:12: error:
• Exception when trying to run compile-time code:
runTest called error: forall (t_0 :: *) . t_0 -> GHC.Types.Bool
diff --git a/testsuite/tests/th/all.T b/testsuite/tests/th/all.T
index 5aa0e4df26..590b060b0b 100644
--- a/testsuite/tests/th/all.T
+++ b/testsuite/tests/th/all.T
@@ -483,3 +483,5 @@ test('T16895e', normal, compile_fail, [''])
test('T16976', normal, compile, [''])
test('T16976f', normal, compile_fail, [''])
test('T16976z', normal, compile_fail, [''])
+test('T16980', normal, compile, [''])
+test('T16980a', normal, compile_fail, [''])