diff options
author | Matthew Pickering <matthewtpickering@gmail.com> | 2021-04-08 11:44:09 +0100 |
---|---|---|
committer | Zubin Duggal <zubin.duggal@gmail.com> | 2021-12-16 16:21:09 +0530 |
commit | 543547fc82da56c8447e2bb7c1422069d959adf8 (patch) | |
tree | 8951c2114a4e69ef1047d33a6f51ea45735056b1 | |
parent | 03336b3f979dbd27a72c7bc973f40ef2dbee50eb (diff) | |
download | haskell-543547fc82da56c8447e2bb7c1422069d959adf8.tar.gz |
template-haskell: Run TH splices with err_vars from current context
Otherwise, errors can go missing which arise when running the splices.
Fixes #19470
(cherry picked from commit da171284ed5119f8c33d1f0a4cc0a0ae52ca5d21)
-rw-r--r-- | compiler/GHC/Tc/Gen/Splice.hs | 6 | ||||
-rw-r--r-- | testsuite/tests/th/T19470.script | 2 | ||||
-rw-r--r-- | testsuite/tests/th/T19470.stderr | 13 | ||||
-rw-r--r-- | testsuite/tests/th/all.T | 1 |
4 files changed, 21 insertions, 1 deletions
diff --git a/compiler/GHC/Tc/Gen/Splice.hs b/compiler/GHC/Tc/Gen/Splice.hs index f2fd31f02a..ae75d93d35 100644 --- a/compiler/GHC/Tc/Gen/Splice.hs +++ b/compiler/GHC/Tc/Gen/Splice.hs @@ -664,7 +664,11 @@ tcTopSplice expr res_ty -- See Note [Running typed splices in the zonker] runTopSplice :: DelayedSplice -> TcM (HsExpr GhcTc) runTopSplice (DelayedSplice lcl_env orig_expr res_ty q_expr) - = setLclEnv lcl_env $ do { + = do + errs_var <- getErrsVar + setLclEnv lcl_env $ setErrsVar errs_var $ do { + -- Set the errs_var to the errs_var from the current context, + -- otherwise error messages can go missing in GHCi (#19470) zonked_ty <- zonkTcType res_ty ; zonked_q_expr <- zonkTopLExpr q_expr -- See Note [Collecting modFinalizers in typed splices]. diff --git a/testsuite/tests/th/T19470.script b/testsuite/tests/th/T19470.script new file mode 100644 index 0000000000..1fb0b3457d --- /dev/null +++ b/testsuite/tests/th/T19470.script @@ -0,0 +1,2 @@ +:set -XTemplateHaskell +print ($$undefined :: String) diff --git a/testsuite/tests/th/T19470.stderr b/testsuite/tests/th/T19470.stderr new file mode 100644 index 0000000000..25b70cd7b8 --- /dev/null +++ b/testsuite/tests/th/T19470.stderr @@ -0,0 +1,13 @@ + +<interactive>:2:10: error: + • Exception when trying to run compile-time code: + Prelude.undefined +CallStack (from HasCallStack): + error, called at libraries/base/GHC/Err.hs:74:14 in base:GHC.Err + undefined, called at <interactive>:2:10 in interactive:Ghci1 + Code: undefined + • In the Template Haskell splice $$undefined + In the first argument of ‘print’, namely ‘($$undefined :: String)’ + In the first argument of ‘GHC.GHCi.ghciStepIO :: + forall a. IO a -> IO a’, namely + ‘(print ($$undefined :: String))’ diff --git a/testsuite/tests/th/all.T b/testsuite/tests/th/all.T index c89b748f82..bb5ca90bc8 100644 --- a/testsuite/tests/th/all.T +++ b/testsuite/tests/th/all.T @@ -514,3 +514,4 @@ test('T18121', normal, compile, ['']) test('T18123', normal, compile, ['']) test('T18388', normal, compile, ['']) test('T20179', normal, compile_fail, ['']) +test('T19470', only_ways(['ghci']), ghci_script, ['T19470.script']) |