fix #10734 by adding braces to pretty-printing of let inside do
authorJohn Leo <leo@halfaya.org>
Sat, 7 Nov 2015 22:28:37 +0000 (17:28 -0500)
committerRichard Eisenberg <eir@cis.upenn.edu>
Sat, 7 Nov 2015 22:31:06 +0000 (17:31 -0500)
Test Plan: validate

Reviewers: bgamari, austin, goldfire

Reviewed By: goldfire

Subscribers: thomie

Differential Revision: https://phabricator.haskell.org/D1448

GHC Trac Issues: #10734

libraries/template-haskell/Language/Haskell/TH/Ppr.hs
testsuite/tests/th/T10734.hs [new file with mode: 0644]
testsuite/tests/th/T10734.stdout [new file with mode: 0644]
testsuite/tests/th/all.T

index 1768b15..2231373 100644 (file)
@@ -184,7 +184,7 @@ pprMaybeExp i (Just e) = pprExp i e
 ------------------------------
 instance Ppr Stmt where
     ppr (BindS p e) = ppr p <+> text "<-" <+> ppr e
-    ppr (LetS ds) = text "let" <+> ppr ds
+    ppr (LetS ds) = text "let" <+> (braces $ sep $ punctuate semi $ map ppr ds)
     ppr (NoBindS e) = ppr e
     ppr (ParS sss) = sep $ punctuate (text "|")
                          $ map (sep . punctuate comma . map ppr) sss
diff --git a/testsuite/tests/th/T10734.hs b/testsuite/tests/th/T10734.hs
new file mode 100644 (file)
index 0000000..05aef86
--- /dev/null
@@ -0,0 +1,10 @@
+{-# LANGUAGE TemplateHaskell #-}
+module Main where
+
+import Language.Haskell.TH
+
+main :: IO ()
+main = do
+  pprint <$> runQ [| do { let { }; return (); } |]             >>= putStrLn
+  pprint <$> runQ [| do { let { x = 5 }; return x; } |]        >>= putStrLn
+  pprint <$> runQ [| do { let { x = 5; y = 3 }; return x; } |] >>= putStrLn
diff --git a/testsuite/tests/th/T10734.stdout b/testsuite/tests/th/T10734.stdout
new file mode 100644 (file)
index 0000000..4a8b39a
--- /dev/null
@@ -0,0 +1,3 @@
+do {let {}; GHC.Base.return GHC.Tuple.()}
+do {let {x_0 = 5}; GHC.Base.return x_0}
+do {let {x_0 = 5; y_1 = 3}; GHC.Base.return x_0}
index 2a040f2..5e8e611 100644 (file)
@@ -364,3 +364,5 @@ test('T10810', normal, compile, ['-v0'])
 test('T10891', normal, compile, ['-v0'])
 test('T10945', normal, compile_fail, ['-v0'])
 test('T10946', expect_broken(10946), compile, ['-v0'])
+test('T10734', normal, compile_and_run, ['-v0'])
+