[commit: ghc] master: Fix TH ppr output for list comprehensions with only one Stmt (0e7ccf6)
git at git.haskell.org
git at git.haskell.org
Sun Sep 11 15:14:54 UTC 2016
Repository : ssh://git@git.haskell.org/ghc
On branch : master
Link : http://ghc.haskell.org/trac/ghc/changeset/0e7ccf6d233c66b23a60de4e35e039f78ea3e162/ghc
>---------------------------------------------------------------
commit 0e7ccf6d233c66b23a60de4e35e039f78ea3e162
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.
>---------------------------------------------------------------
0e7ccf6d233c66b23a60de4e35e039f78ea3e162
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 0462a8d..7376135 100644
--- a/libraries/template-haskell/Language/Haskell/TH/Ppr.hs
+++ b/libraries/template-haskell/Language/Haskell/TH/Ppr.hs
@@ -179,12 +179,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
- <+> bar
- <+> 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
+ <+> bar
+ <+> 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