summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--compiler/typecheck/TcSplice.hs6
-rw-r--r--testsuite/tests/th/T13837.hs10
-rw-r--r--testsuite/tests/th/T13837.stderr10
-rw-r--r--testsuite/tests/th/all.T1
4 files changed, 26 insertions, 1 deletions
diff --git a/compiler/typecheck/TcSplice.hs b/compiler/typecheck/TcSplice.hs
index 824227a60c..266a4dfe3a 100644
--- a/compiler/typecheck/TcSplice.hs
+++ b/compiler/typecheck/TcSplice.hs
@@ -1138,7 +1138,11 @@ reifyInstances th_nm th_tys
; let tv_rdrs = freeKiTyVarsAllVars free_vars
-- Rename to HsType Name
; ((tv_names, rn_ty), _fvs)
- <- bindLRdrNames tv_rdrs $ \ tv_names ->
+ <- checkNoErrs $ -- If there are out-of-scope Names here, then we
+ -- must error before proceeding to typecheck the
+ -- renamed type, as that will result in GHC
+ -- internal errors (#13837).
+ bindLRdrNames tv_rdrs $ \ tv_names ->
do { (rn_ty, fvs) <- rnLHsType doc rdr_ty
; return ((tv_names, rn_ty), fvs) }
; (_tvs, ty)
diff --git a/testsuite/tests/th/T13837.hs b/testsuite/tests/th/T13837.hs
new file mode 100644
index 0000000000..3d33341e4d
--- /dev/null
+++ b/testsuite/tests/th/T13837.hs
@@ -0,0 +1,10 @@
+{-# LANGUAGE TemplateHaskell #-}
+module T13837 where
+
+import Language.Haskell.TH.Lib
+import Language.Haskell.TH.Syntax
+
+test_local_tyfam_expansion :: String
+test_local_tyfam_expansion =
+ $(do fam_name <- newName "Fam"
+ stringE . show =<< qReifyInstances fam_name [])
diff --git a/testsuite/tests/th/T13837.stderr b/testsuite/tests/th/T13837.stderr
new file mode 100644
index 0000000000..53700b5a7a
--- /dev/null
+++ b/testsuite/tests/th/T13837.stderr
@@ -0,0 +1,10 @@
+
+T13837.hs:9:5: error:
+ • The exact Name ‘Fam’ is not in scope
+ Probable cause: you used a unique Template Haskell name (NameU),
+ perhaps via newName, but did not bind it
+ If that's it, then -ddump-splices might be useful
+ • In the argument of reifyInstances: Fam_0
+ In the untyped splice:
+ $(do fam_name <- newName "Fam"
+ stringE . show =<< qReifyInstances fam_name [])
diff --git a/testsuite/tests/th/all.T b/testsuite/tests/th/all.T
index df31162c3e..b52042bb76 100644
--- a/testsuite/tests/th/all.T
+++ b/testsuite/tests/th/all.T
@@ -389,5 +389,6 @@ test('T13618', normal, compile_and_run, ['-v0'])
test('T13642', normal, compile_fail, ['-v0'])
test('T13781', normal, compile, ['-v0'])
test('T13782', normal, compile, [''])
+test('T13837', normal, compile_fail, ['-v0 -dsuppress-uniques'])
test('T13856', normal, compile, ['-v0 -ddump-splices -dsuppress-uniques'])
test('T13968', normal, compile_fail, ['-v0'])