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

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

On branch  : master

http://hackage.haskell.org/trac/ghc/changeset/a501c950652d3cb56335781289f0f502c0cf2f4e

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

commit a501c950652d3cb56335781289f0f502c0cf2f4e
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 21a6b7e..c5f0af3 100644
--- a/compiler/typecheck/TcSplice.lhs
+++ b/compiler/typecheck/TcSplice.lhs
@@ -497,6 +497,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.