summaryrefslogtreecommitdiff
path: root/compiler
diff options
context:
space:
mode:
authorsimonpj@microsoft.com <unknown>2009-11-05 12:07:33 +0000
committersimonpj@microsoft.com <unknown>2009-11-05 12:07:33 +0000
commit830f4b00a7299dfa742c89e13e861f310d804642 (patch)
tree16341521dded5c8e9d96023b3bbef90b84a743fe /compiler
parent8f53119f5772a8c8dc9fd08065cc86df7a4f0b26 (diff)
downloadhaskell-830f4b00a7299dfa742c89e13e861f310d804642.tar.gz
Improve error reporting when there's an error inside a spliced expression
If an error occurs in *spliced* code, it can be tricky to understand what is going on. With this patch, in - epxressions - types we give a helpful indicator that it's in the result of a splice. For declarations it's harder, because they get type-checked in a group with other non-spliced decls, so I have not made the same improvement. But it's still better than it was.
Diffstat (limited to 'compiler')
-rw-r--r--compiler/typecheck/TcSplice.lhs19
1 files changed, 13 insertions, 6 deletions
diff --git a/compiler/typecheck/TcSplice.lhs b/compiler/typecheck/TcSplice.lhs
index 651d44c6c3..70eaca8cec 100644
--- a/compiler/typecheck/TcSplice.lhs
+++ b/compiler/typecheck/TcSplice.lhs
@@ -438,10 +438,17 @@ tcTopSplice expr res_ty
-- Rename it, but bale out if there are errors
-- otherwise the type checker just gives more spurious errors
- ; (exp3, _fvs) <- checkNoErrs (rnLExpr expr2)
+ ; addErrCtxt (spliceResultDoc expr) $ do
+ { (exp3, _fvs) <- checkNoErrs (rnLExpr expr2)
- ; exp4 <- tcMonoExpr exp3 res_ty
- ; return (unLoc exp4) }
+ ; exp4 <- tcMonoExpr exp3 res_ty
+ ; return (unLoc exp4) } }
+
+spliceResultDoc :: LHsExpr Name -> SDoc
+spliceResultDoc expr
+ = sep [ ptext (sLit "In the result of the splice:")
+ , nest 2 (char '$' <> pprParendExpr expr)
+ , ptext (sLit "To see what the splice expanded to, use -ddump-splices")]
-------------------
tcTopSpliceExpr :: TcM (LHsExpr Id) -> TcM (LHsExpr Id)
@@ -522,11 +529,11 @@ kcTopSpliceType expr
-- Rename it, but bale out if there are errors
-- otherwise the type checker just gives more spurious errors
- ; let doc = ptext (sLit "In the spliced type") <+> ppr hs_ty2
+ ; addErrCtxt (spliceResultDoc expr) $ do
+ { let doc = ptext (sLit "In the spliced type") <+> ppr hs_ty2
; hs_ty3 <- checkNoErrs (rnLHsType doc hs_ty2)
-
; (ty4, kind) <- kcLHsType hs_ty3
- ; return (unLoc ty4, kind) }
+ ; return (unLoc ty4, kind) }}
\end{code}
%************************************************************************