summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorElton <eltonp3103@gmail.com>2022-01-04 18:28:27 -0500
committerMarge Bot <ben+marge-bot@smart-cactus.org>2022-02-01 12:28:49 -0500
commit60ac73002fc6fb717f1838a2bb3cee6535ff77c9 (patch)
tree361d811a8e909bcbad69d14c42f2b3ac3d9f869e
parent584f03faed67c59895c90900ededb715a1a62528 (diff)
downloadhaskell-60ac73002fc6fb717f1838a2bb3cee6535ff77c9.tar.gz
Use braces in TH case pprint (fixes #20893)
This patch ensures that the pretty printer formats `case` statements using braces (instead of layout) to remain consistent with the formatting of other statements (like `do`)
-rw-r--r--libraries/template-haskell/Language/Haskell/TH/Ppr.hs2
-rw-r--r--testsuite/tests/quotes/T20893.hs29
-rw-r--r--testsuite/tests/quotes/T20893.stdout14
-rw-r--r--testsuite/tests/quotes/all.T1
4 files changed, 45 insertions, 1 deletions
diff --git a/libraries/template-haskell/Language/Haskell/TH/Ppr.hs b/libraries/template-haskell/Language/Haskell/TH/Ppr.hs
index 02f38852ac..42d32487c8 100644
--- a/libraries/template-haskell/Language/Haskell/TH/Ppr.hs
+++ b/libraries/template-haskell/Language/Haskell/TH/Ppr.hs
@@ -183,7 +183,7 @@ pprExp i (LetE ds_ e) = parensIf (i > noPrec) $ text "let" <+> pprDecs ds_
pprExp i (CaseE e ms)
= parensIf (i > noPrec) $ text "case" <+> ppr e <+> text "of"
- $$ nest nestDepth (ppr ms)
+ $$ braces (semiSep ms)
pprExp i (DoE m ss_) = parensIf (i > noPrec) $
pprQualifier m <> text "do" <+> pprStms ss_
where
diff --git a/testsuite/tests/quotes/T20893.hs b/testsuite/tests/quotes/T20893.hs
new file mode 100644
index 0000000000..90f1efb331
--- /dev/null
+++ b/testsuite/tests/quotes/T20893.hs
@@ -0,0 +1,29 @@
+-- #20893
+
+module Main where
+
+import Language.Haskell.TH
+import Language.Haskell.TH.Ppr
+
+main = do
+ runQ t1 >>= p
+ runQ t2 >>= p
+
+t1 = [d| main = do { case 0 of { 0 -> 1 }; putStrLn "pass" } |]
+
+t2 = [d|
+ main = do
+ let day = "mon"
+ let num = case day of
+ "mon" -> 0
+ "tue" -> 1
+ "wed" -> 3
+ "thu" -> 4
+ "fri" -> 5
+ "sat" -> 6
+ "sun" -> 7
+ _ -> 8
+ putStrLn (show day) ++ " is " (show num)
+ |]
+
+p = putStrLn . pprint
diff --git a/testsuite/tests/quotes/T20893.stdout b/testsuite/tests/quotes/T20893.stdout
new file mode 100644
index 0000000000..c08abdd03d
--- /dev/null
+++ b/testsuite/tests/quotes/T20893.stdout
@@ -0,0 +1,14 @@
+main_0 = do {case 0 of
+ {0 -> 1};
+ System.IO.putStrLn "pass"}
+main_0 = do {let {day_1 = "mon"};
+ let {num_2 = case day_1 of
+ {"mon" -> 0;
+ "tue" -> 1;
+ "wed" -> 3;
+ "thu" -> 4;
+ "fri" -> 5;
+ "sat" -> 6;
+ "sun" -> 7;
+ _ -> 8}};
+ System.IO.putStrLn (GHC.Show.show day_1) GHC.Base.++ " is " (GHC.Show.show num_2)} \ No newline at end of file
diff --git a/testsuite/tests/quotes/all.T b/testsuite/tests/quotes/all.T
index e441811111..1d145e8781 100644
--- a/testsuite/tests/quotes/all.T
+++ b/testsuite/tests/quotes/all.T
@@ -39,3 +39,4 @@ test('TH_top_splice', normal, compile_fail, [''])
test('TTH_top_splice', normal, compile_fail, [''])
test('TH_double_splice', normal, compile_fail, [''])
test('T20688', normal, compile, ['-Wimplicit-lift -Werror'])
+test('T20893', normal, compile_and_run, [''])