From 50837615c7e1d1d6b703e99ee7fd8fcf0bfee30c Mon Sep 17 00:00:00 2001 From: Simon Peyton Jones <simonpj@microsoft.com> Date: Mon, 1 Oct 2012 21:52:19 +0100 Subject: [PATCH] Make sure that we check for type errors strictly in a Template Haskell splice, even if -fdefer-type-errors is on We're going to run this code, so there's no point in deferring type errors. Worse, TcSplice uses unsafeCoerce (for vevy good reasons), so splicing a type into a place where an expression is expected would yield a seg-fault if we plough on regardless. Fixes Trac #7276 --- compiler/typecheck/TcSplice.lhs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/compiler/typecheck/TcSplice.lhs b/compiler/typecheck/TcSplice.lhs index 21d0a1dd5c1f..3b5687399f82 100644 --- a/compiler/typecheck/TcSplice.lhs +++ b/compiler/typecheck/TcSplice.lhs @@ -496,6 +496,12 @@ tcTopSpliceExpr :: TcM (LHsExpr Id) -> TcM (LHsExpr Id) tcTopSpliceExpr tc_action = checkNoErrs $ -- checkNoErrs: must not try to run the thing -- if the type checker fails! + unsetDOptM Opt_DeferTypeErrors $ + -- Don't defer type errors. Not only are we + -- going to run this code, but we do an unsafe + -- coerce, so we get a seg-fault if, say we + -- splice a type into a place where an expression + -- is expected (Trac #7276) setStage Splice $ do { -- Typecheck the expression (expr', lie) <- captureConstraints tc_action -- GitLab