From: Ian Lynagh Date: Sun, 13 Jun 2010 15:48:38 +0000 (+0000) Subject: Fix printing of splices; part of #4124 X-Git-Url: http://git.megacz.com/?p=ghc-hetmet.git;a=commitdiff_plain;h=127d259f77deda6f03c2213c3dacba0354b37322 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. --- 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 |]