[commit: ghc] ghc-8.0: Fix TH ppr output for list comprehensions with only one Stmt (43149ea)
git at git.haskell.org
git at git.haskell.org
Mon Sep 12 16:17:05 UTC 2016
Repository : ssh://git@git.haskell.org/ghc
On branch : ghc-8.0
Link : http://ghc.haskell.org/trac/ghc/changeset/43149ea634a99e125bf7e1750953945d04df823b/ghc
>---------------------------------------------------------------
commit 43149ea634a99e125bf7e1750953945d04df823b
Author: Ryan Scott <ryan.gl.scott at gmail.com>
Date: Sun Sep 11 11:10:36 2016 -0400
Fix TH ppr output for list comprehensions with only one Stmt
A folow-up to D2521 (which addressed #12583), where the `Outputable` `ppr`
output was tweaked to display a list comprehension with only one `Stmt` as
`[Foo]` instead of `[Foo|]` (which isn't valid Haskell). I forgot to update
the corresponding code in `Language.Haskell.TH.Ppr` which pretty-prints
`CompE`, however, so this commit takes care of that.
(cherry picked from commit 0e7ccf6d233c66b23a60de4e35e039f78ea3e162)
>---------------------------------------------------------------
43149ea634a99e125bf7e1750953945d04df823b
libraries/template-haskell/Language/Haskell/TH/Ppr.hs | 17 +++++++++++------
1 file changed, 11 insertions(+), 6 deletions(-)
diff --git a/libraries/template-haskell/Language/Haskell/TH/Ppr.hs b/libraries/template-haskell/Language/Haskell/TH/Ppr.hs
index 2a56620..a57eeff 100644
--- a/libraries/template-haskell/Language/Haskell/TH/Ppr.hs
+++ b/libraries/template-haskell/Language/Haskell/TH/Ppr.hs
@@ -159,12 +159,17 @@ pprExp i (DoE ss_) = parensIf (i > noPrec) $ text "do" <+> pprStms ss_
pprExp _ (CompE []) = text "<<Empty CompExp>>"
-- This will probably break with fixity declarations - would need a ';'
-pprExp _ (CompE ss) = text "[" <> ppr s
- <+> text "|"
- <+> commaSep ss'
- <> text "]"
- where s = last ss
- ss' = init ss
+pprExp _ (CompE ss) =
+ if null ss'
+ -- If there are no statements in a list comprehension besides the last
+ -- one, we simply treat it like a normal list.
+ then text "[" <> ppr s <> text "]"
+ else text "[" <> ppr s
+ <+> text "|"
+ <+> commaSep ss'
+ <> text "]"
+ where s = last ss
+ ss' = init ss
pprExp _ (ArithSeqE d) = ppr d
pprExp _ (ListE es) = brackets (commaSep es)
pprExp i (SigE e t) = parensIf (i > noPrec) $ ppr e <+> dcolon <+> ppr t
More information about the ghc-commits
mailing list