Parenthesize forall-type args in cvtTypeKind
authorRyan Scott <ryan.gl.scott@gmail.com>
Mon, 15 Jan 2018 18:51:55 +0000 (13:51 -0500)
committerBen Gamari <ben@smart-cactus.org>
Mon, 15 Jan 2018 18:53:46 +0000 (13:53 -0500)
Trac #14646 happened because we forgot to parenthesize `forall` types to
the left of an arrow. This simple patch fixes that.

Test Plan: make test TEST=T14646

Reviewers: alanz, goldfire, bgamari

Reviewed By: alanz

Subscribers: rwbarton, thomie, carter

GHC Trac Issues: #14646

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

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

index de72878..e8c7f0d 100644 (file)
@@ -1219,10 +1219,11 @@ cvtTypeKind ty_str ty
                         tys'
            ArrowT
              | [x',y'] <- tys' -> do
-                 case x' of
-                   (L _ HsFunTy{}) -> do { x'' <- returnL (HsParTy x')
-                                         ; returnL (HsFunTy x'' y') }
-                   _  -> returnL (HsFunTy x' y')
+                 x'' <- case x' of
+                          L _ HsFunTy{}    -> returnL (HsParTy x')
+                          L _ HsForAllTy{} -> returnL (HsParTy x') -- #14646
+                          _                -> return x'
+                 returnL (HsFunTy x'' y')
              | otherwise ->
                   mk_apps (HsTyVar NotPromoted (noLoc (getRdrName funTyCon)))
                           tys'
diff --git a/testsuite/tests/th/T14646.hs b/testsuite/tests/th/T14646.hs
new file mode 100644 (file)
index 0000000..c858723
--- /dev/null
@@ -0,0 +1,6 @@
+{-# LANGUAGE RankNTypes #-}
+{-# LANGUAGE TemplateHaskell #-}
+module T14646 where
+
+$([d| f :: (forall a. a) -> Int
+      f _ = undefined |])
diff --git a/testsuite/tests/th/T14646.stderr b/testsuite/tests/th/T14646.stderr
new file mode 100644 (file)
index 0000000..869cf6f
--- /dev/null
@@ -0,0 +1,6 @@
+T14646.hs:(5,3)-(6,24): Splicing declarations
+    [d| f :: (forall a. a) -> Int
+        f _ = undefined |]
+  ======>
+    f :: (forall a. a) -> Int
+    f _ = undefined
index 0ad178e..1fae4c6 100644 (file)
@@ -397,3 +397,4 @@ test('T13887', normal, compile_and_run, ['-v0'])
 test('T13968', normal, compile_fail, ['-v0'])
 test('T14204', normal, compile_fail, ['-v0'])
 test('T14060', normal, compile_and_run, ['-v0'])
+test('T14646', normal, compile, ['-v0 -ddump-splices -dsuppress-uniques'])