[commit: ghc] ghc-7.6: Make sure that we check for type errors strictly in a Template Haskell splice, even if -fdefer-type-errors is on (5083761)

Ian Lynagh <[email protected]>
Newsgroups gmane.comp.lang.haskell.cvs.ghc
Message-ID <[email protected]>
Repository : ssh://darcs.haskell.org//srv/darcs/ghc

On branch  : ghc-7.6

http://hackage.haskell.org/trac/ghc/changeset/50837615c7e1d1d6b703e99ee7fd8fcf0bfee30c

>---------------------------------------------------------------

commit 50837615c7e1d1d6b703e99ee7fd8fcf0bfee30c
Author: Simon Peyton Jones <[email protected]>
Date:   Mon Oct 1 21:52:19 2012 +0100

    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 files changed, 6 insertions(+), 0 deletions(-)

diff --git a/compiler/typecheck/TcSplice.lhs b/compiler/typecheck/TcSplice.lhs
index 21d0a1d..3b56873 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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.