[commit: template-haskell] master: In the Template Haskell pretty printer, don't call error (d7b864b)
Simon Peyton Jones
simonpj at microsoft.com
Tue Sep 18 12:48:26 CEST 2012
Repository : ssh://darcs.haskell.org//srv/darcs/packages/template-haskell
On branch : master
http://hackage.haskell.org/trac/ghc/changeset/d7b864b7ddb0e8c2f58d08dfd50e843eb8966b90
>---------------------------------------------------------------
commit d7b864b7ddb0e8c2f58d08dfd50e843eb8966b90
Author: Simon Peyton Jones <simonpj at microsoft.com>
Date: Tue Sep 18 11:48:05 2012 +0100
In the Template Haskell pretty printer, don't call error
There were two cases in which we called error
* An InfixE with an operator epxression other than VarE or ConE
* A comprehension with empty Stmts, ie CompE []
Crashing doesn't help much. Now the library puts in the pretty
printed output a textual signal about what went wrong.
This addresses the crash in Trac #7235, although doesn't fix
the underlying cause, which remains shrouded in obscurity.
>---------------------------------------------------------------
Language/Haskell/TH/Ppr.hs | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/Language/Haskell/TH/Ppr.hs b/Language/Haskell/TH/Ppr.hs
index 4de7588..60b9c01 100644
--- a/Language/Haskell/TH/Ppr.hs
+++ b/Language/Haskell/TH/Ppr.hs
@@ -84,7 +84,7 @@ instance Ppr Exp where
pprInfixExp :: Exp -> Doc
pprInfixExp (VarE v) = pprName' Infix v
pprInfixExp (ConE v) = pprName' Infix v
-pprInfixExp _ = error "Attempt to pretty-print non-variable or constructor in infix context!"
+pprInfixExp _ = text "<<Non-variable/constructor in infix context>>"
pprExp :: Precedence -> Exp -> Doc
pprExp _ (VarE v) = pprName' Applied v
@@ -127,7 +127,7 @@ pprExp i (CaseE e ms)
= parensIf (i > noPrec) $ text "case" <+> ppr e <+> text "of"
$$ nest nestDepth (ppr ms)
pprExp i (DoE ss) = parensIf (i > noPrec) $ text "do" <+> ppr ss
-pprExp _ (CompE []) = error "Can't happen: pprExp (CompExp [])"
+pprExp _ (CompE []) = text "<<Empty CompExp>>"
-- This will probably break with fixity declarations - would need a ';'
pprExp _ (CompE ss) = text "[" <> ppr s
<+> text "|"
More information about the Cvs-libraries
mailing list