summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Peyton Jones <simonpj@microsoft.com>2021-07-30 09:38:54 +0100
committerZubin Duggal <zubin.duggal@gmail.com>2021-09-21 22:28:30 +0530
commit68984c2a1181576c9eb0e20c9e4821334a40f197 (patch)
tree655399b2a6a935f7170e8d96db9b6a7cd614d60c
parentd94243f71035c4129c90bd328ac71bb0dc7d88ac (diff)
downloadhaskell-68984c2a1181576c9eb0e20c9e4821334a40f197.tar.gz
Catch type-checker exceptions when splicing
In GHC.Tc.Gen.Splice.tcTopSpliceExpr we were forgetting to catch exceptions. As a result we missed the kind error in the unsolved constraints. This patch has an easy fix, which cures #20179 (cherry picked from commit eff51e2aca978ebd0ca08345fb1790d70f6bb7c8)
-rw-r--r--compiler/GHC/Tc/Gen/Splice.hs14
-rw-r--r--testsuite/tests/th/T20179.hs7
-rw-r--r--testsuite/tests/th/T20179.stderr10
-rw-r--r--testsuite/tests/th/all.T1
4 files changed, 28 insertions, 4 deletions
diff --git a/compiler/GHC/Tc/Gen/Splice.hs b/compiler/GHC/Tc/Gen/Splice.hs
index 998f03a5d5..f2fd31f02a 100644
--- a/compiler/GHC/Tc/Gen/Splice.hs
+++ b/compiler/GHC/Tc/Gen/Splice.hs
@@ -735,11 +735,17 @@ tcTopSpliceExpr isTypedSplice tc_action
-- is expected (#7276)
setStage (Splice isTypedSplice) $
do { -- Typecheck the expression
- (expr', wanted) <- captureConstraints tc_action
- ; const_binds <- simplifyTop wanted
+ (mb_expr', wanted) <- tryCaptureConstraints tc_action
+ -- If tc_action fails (perhaps because of insoluble constraints)
+ -- we want to capture and report those constraints, else we may
+ -- just get a silent failure (#20179). Hence the 'try' part.
- -- Zonk it and tie the knot of dictionary bindings
- ; return $ mkHsDictLet (EvBinds const_binds) expr' }
+ ; const_binds <- simplifyTop wanted
+
+ ; case mb_expr' of
+ Nothing -> failM -- In this case simplifyTop should have
+ -- reported some errors
+ Just expr' -> return $ mkHsDictLet (EvBinds const_binds) expr' }
{-
************************************************************************
diff --git a/testsuite/tests/th/T20179.hs b/testsuite/tests/th/T20179.hs
new file mode 100644
index 0000000000..a01f573979
--- /dev/null
+++ b/testsuite/tests/th/T20179.hs
@@ -0,0 +1,7 @@
+{-# LANGUAGE TemplateHaskell #-}
+module Bug where
+
+$(let slurmp :: [Maybe]
+ slurmp = []
+
+ in pure [])
diff --git a/testsuite/tests/th/T20179.stderr b/testsuite/tests/th/T20179.stderr
new file mode 100644
index 0000000000..28eb54d698
--- /dev/null
+++ b/testsuite/tests/th/T20179.stderr
@@ -0,0 +1,10 @@
+
+T20179.hs:4:18: error:
+ • Expecting one more argument to ‘Maybe’
+ Expected a type, but ‘Maybe’ has kind ‘* -> *’
+ • In the type signature: slurmp :: [Maybe]
+ In the expression:
+ let
+ slurmp :: [Maybe]
+ slurmp = []
+ in pure []
diff --git a/testsuite/tests/th/all.T b/testsuite/tests/th/all.T
index 6d4a5036d7..c89b748f82 100644
--- a/testsuite/tests/th/all.T
+++ b/testsuite/tests/th/all.T
@@ -513,3 +513,4 @@ test('T18102b', extra_files(['T18102b_aux.hs']), compile_and_run, [''])
test('T18121', normal, compile, [''])
test('T18123', normal, compile, [''])
test('T18388', normal, compile, [''])
+test('T20179', normal, compile_fail, [''])