From 127d259f77deda6f03c2213c3dacba0354b37322 Mon Sep 17 00:00:00 2001 From: Ian Lynagh Date: Sun, 13 Jun 2010 15:48:38 +0000 Subject: [PATCH] Fix printing of splices; part of #4124 Just putting parens around non-atomic expressions isn't sufficient for splices, as only the $x and $(e) forms are valid input. --- compiler/hsSyn/HsExpr.lhs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/compiler/hsSyn/HsExpr.lhs b/compiler/hsSyn/HsExpr.lhs index 7930caa..84901ee 100644 --- a/compiler/hsSyn/HsExpr.lhs +++ b/compiler/hsSyn/HsExpr.lhs @@ -1066,8 +1066,16 @@ instance OutputableBndr id => Outputable (HsSplice id) where pprSplice :: OutputableBndr id => HsSplice id -> SDoc pprSplice (HsSplice n e) - = char '$' <> ifPprDebug (brackets (ppr n)) <> pprParendExpr e - + = char '$' <> ifPprDebug (brackets (ppr n)) <> eDoc + where + -- We use pprLExpr to match pprParendExpr: + -- Using pprLExpr makes sure that we go 'deeper' + -- I think that is usually (always?) right + pp_as_was = pprLExpr e + eDoc = case unLoc e of + HsPar _ -> pp_as_was + HsVar _ -> pp_as_was + _ -> parens pp_as_was data HsBracket id = ExpBr (LHsExpr id) -- [| expr |] | PatBr (LPat id) -- [p| pat |] -- 1.7.10.4