Properly designate LambdaCase alts as CaseAlt in TH
authorRyan Scott <ryan.gl.scott@gmail.com>
Tue, 14 Aug 2018 20:35:23 +0000 (22:35 +0200)
committerBen Gamari <ben@smart-cactus.org>
Thu, 23 Aug 2018 22:50:28 +0000 (18:50 -0400)
Summary:
When `\case` expressions are parsed normally, their
alternatives are marked as `CaseAlt` (which means that they are
pretty-printed without a `\` character in front of them, unlike for
lambda expressions). However, `\case` expressions created by way of
Template Haskell (in `Convert`) inconsistently designated the case
alternatives as `LambdaExpr`, causing them to be pretty-printed
poorly (as shown in #15518). The fix is simple: use `CaseAlt`
consistently.

Test Plan: make test TEST=T15518

Reviewers: goldfire, bgamari

Subscribers: rwbarton, carter

GHC Trac Issues: #15518

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

(cherry picked from commit 32008a9d0e09f0cc8899aa871d9a6b63fcc28a1a)

compiler/hsSyn/Convert.hs
testsuite/tests/th/T15518.hs [new file with mode: 0644]
testsuite/tests/th/T15518.stderr [new file with mode: 0644]
testsuite/tests/th/all.T

index c64cb7c..b637a3c 100644 (file)
@@ -829,7 +829,7 @@ cvtl e = wrapL (cvt e)
                             ; return $ HsLam noExt (mkMatchGroup FromSource
                                              [mkSimpleMatch LambdaExpr
                                              pats e'])}
-    cvt (LamCaseE ms)  = do { ms' <- mapM (cvtMatch LambdaExpr) ms
+    cvt (LamCaseE ms)  = do { ms' <- mapM (cvtMatch CaseAlt) ms
                             ; return $ HsLamCase noExt
                                                    (mkMatchGroup FromSource ms')
                             }
diff --git a/testsuite/tests/th/T15518.hs b/testsuite/tests/th/T15518.hs
new file mode 100644 (file)
index 0000000..eb424a9
--- /dev/null
@@ -0,0 +1,8 @@
+{-# LANGUAGE LambdaCase #-}
+{-# LANGUAGE TemplateHaskell #-}
+module T15518 where
+
+$([d| f :: Bool -> ()
+      f = \case True  -> ()
+                False -> ()
+    |])
diff --git a/testsuite/tests/th/T15518.stderr b/testsuite/tests/th/T15518.stderr
new file mode 100644 (file)
index 0000000..7d9ef29
--- /dev/null
@@ -0,0 +1,10 @@
+T15518.hs:(5,3)-(8,6): Splicing declarations
+    [d| f :: Bool -> ()
+        f = \case
+              True -> ()
+              False -> () |]
+  ======>
+    f :: Bool -> ()
+    f = \case
+          True -> ()
+          False -> ()
index f6656c4..ebdd2ce 100644 (file)
@@ -419,3 +419,4 @@ test('T15331', normal, compile, ['-v0 -ddump-splices -dsuppress-uniques'])
 test('T15324', normal, compile, ['-v0 -ddump-splices -dsuppress-uniques'])
 test('T15321', normal, compile_fail, [''])
 test('T15365', normal, compile, ['-v0 -ddump-splices -dsuppress-uniques'])
+test('T15518', normal, compile, ['-v0 -ddump-splices -dsuppress-uniques'])