summaryrefslogtreecommitdiff
path: root/testsuite/tests
diff options
context:
space:
mode:
authorMatthew Pickering <matthewtpickering@gmail.com>2022-05-18 12:15:39 +0100
committerMarge Bot <ben+marge-bot@smart-cactus.org>2022-05-22 21:57:47 -0400
commitea895b94afeecb111f8001fbd60f5d4c8828213c (patch)
treed7f4da05089794e796a8a805b48dc59319001988 /testsuite/tests
parent7edd991e5d00a1ba19f3607fe8a66bbdc3ab3181 (diff)
downloadhaskell-ea895b94afeecb111f8001fbd60f5d4c8828213c.tar.gz
Consider the stage of typeable evidence when checking stage restriction
We were considering all Typeable evidence to be "BuiltinInstance"s which meant the stage restriction was going unchecked. In-fact, typeable has evidence and so we need to apply the stage restriction. This is complicated by the fact we don't generate typeable evidence and the corresponding DFunIds until after typechecking is concluded so we introcue a new `InstanceWhat` constructor, BuiltinTypeableInstance which records whether the evidence is going to be local or not. Fixes #21547
Diffstat (limited to 'testsuite/tests')
-rw-r--r--testsuite/tests/th/T21547.hs11
-rw-r--r--testsuite/tests/th/T21547.stderr9
-rw-r--r--testsuite/tests/th/T21547A.hs9
-rw-r--r--testsuite/tests/th/all.T1
4 files changed, 30 insertions, 0 deletions
diff --git a/testsuite/tests/th/T21547.hs b/testsuite/tests/th/T21547.hs
new file mode 100644
index 0000000000..99b9992c59
--- /dev/null
+++ b/testsuite/tests/th/T21547.hs
@@ -0,0 +1,11 @@
+{-# LANGUAGE TemplateHaskell #-}
+module T21547 where
+import T21547A
+
+data T a = T a deriving (Show)
+
+main :: IO ()
+main = do
+ let x = $$(foo [|| T () ||])
+ let y = $$(foo [|| F () ||])
+ return ()
diff --git a/testsuite/tests/th/T21547.stderr b/testsuite/tests/th/T21547.stderr
new file mode 100644
index 0000000000..a37b98aa85
--- /dev/null
+++ b/testsuite/tests/th/T21547.stderr
@@ -0,0 +1,9 @@
+
+T21547.hs:9:14: error:
+ • GHC stage restriction:
+ instance for ‘base-4.16.0.0:Data.Typeable.Internal.Typeable
+ T’ is used in a top-level splice, quasi-quote, or annotation,
+ and must be imported, not defined locally
+ • In the expression: foo [|| T () ||]
+ In the Template Haskell splice $$(foo [|| T () ||])
+ In the expression: $$(foo [|| T () ||])
diff --git a/testsuite/tests/th/T21547A.hs b/testsuite/tests/th/T21547A.hs
new file mode 100644
index 0000000000..19b47f8987
--- /dev/null
+++ b/testsuite/tests/th/T21547A.hs
@@ -0,0 +1,9 @@
+module T21547A where
+
+import Data.Typeable
+import Language.Haskell.TH
+
+foo :: Typeable a => Code Q a -> Code Q ()
+foo = undefined
+
+data F a = F a deriving (Show)
diff --git a/testsuite/tests/th/all.T b/testsuite/tests/th/all.T
index ec79e19249..7147fa4182 100644
--- a/testsuite/tests/th/all.T
+++ b/testsuite/tests/th/all.T
@@ -543,6 +543,7 @@ test('T17820c', normal, compile_fail, [''])
test('T17820d', normal, compile_fail, [''])
test('T17820e', normal, compile_fail, [''])
test('T20454', normal, compile_and_run, [''])
+test('T21547', [extra_files(['T21547A.hs'])], multimod_compile_fail, ['T21547', '-v0'])
test('T20590', normal, compile, ['-v0 -ddump-splices -dsuppress-uniques'])
test('T20773', only_ways(['ghci']), ghci_script, ['T20773.script'])
test('T20884', normal, compile_fail, [''])