Tweak API Annotations for ConDeclGADT
authorAlan Zimmerman <alan.zimm@gmail.com>
Sun, 24 Jun 2018 20:00:22 +0000 (22:00 +0200)
committerBen Gamari <ben@smart-cactus.org>
Mon, 25 Jun 2018 22:08:56 +0000 (18:08 -0400)
(cherry picked from commit 5db9f9129e7519db0c9841fbe7c14f350c23284c)

compiler/parser/Parser.y
compiler/parser/RdrHsSyn.hs
testsuite/tests/ghc-api/annotations/T10255.stdout
testsuite/tests/ghc-api/annotations/T10278.stdout
testsuite/tests/ghc-api/annotations/T10312.stdout
testsuite/tests/ghc-api/annotations/T10399.stdout
testsuite/tests/ghc-api/annotations/T11018.stdout
testsuite/tests/ghc-api/annotations/exampleTest.stdout
testsuite/tests/ghc-api/annotations/parseTree.stdout

index 0e93dd0..6b0317b 100644 (file)
@@ -1882,7 +1882,8 @@ is connected to the first type too.
 
 type :: { LHsType GhcPs }
         : btype                        { $1 }
-        | btype '->' ctype             {% ams (sLL $1 $> $ HsFunTy noExt $1 $3)
+        | btype '->' ctype             {% ams $1 [mu AnnRarrow $2] -- See note [GADT decl discards annotations]
+                                       >> ams (sLL $1 $> $ HsFunTy noExt $1 $3)
                                               [mu AnnRarrow $2] }
 
 
index aed5c5d..a74d98a 100644 (file)
@@ -649,7 +649,7 @@ mkGadtDecl names ty
                  , con_args   = args'
                  , con_res_ty = res_ty
                  , con_doc    = Nothing }
-    , anns1 ++ anns2 ++ anns3)
+    , anns1 ++ anns2)
   where
     (ty'@(L l _),anns1) = peel_parens ty []
     (tvs, rho) = splitLHsForAllTy ty'
@@ -660,14 +660,13 @@ mkGadtDecl names ty
     split_rho (L l (HsParTy _ ty)) ann = split_rho ty (ann++mkParensApiAnn l)
     split_rho tau                  ann = (Nothing, tau, ann)
 
-    (args, res_ty, anns3) = split_tau tau []
+    (args, res_ty) = split_tau tau
     args' = nudgeHsSrcBangs args
 
     -- See Note [GADT abstract syntax] in HsDecls
-    split_tau (L _ (HsFunTy _ (L loc (HsRecTy _ rf)) res_ty)) ann
-                                       = (RecCon (L loc rf), res_ty, ann)
-    split_tau (L l (HsParTy _ ty)) ann = split_tau ty (ann++mkParensApiAnn l)
-    split_tau tau                  ann = (PrefixCon [], tau, ann)
+    split_tau (L _ (HsFunTy _ (L loc (HsRecTy _ rf)) res_ty))
+                                   = (RecCon (L loc rf), res_ty)
+    split_tau tau                  = (PrefixCon [], tau)
 
     peel_parens (L l (HsParTy _ ty)) ann = peel_parens ty
                                                        (ann++mkParensApiAnn l)
index 994c76f..494136d 100644 (file)
@@ -16,6 +16,7 @@
 ((Test10255.hs:6:6-26,AnnDcolon), [Test10255.hs:6:8-9]),
 ((Test10255.hs:6:11-26,AnnCloseP), [Test10255.hs:6:26]),
 ((Test10255.hs:6:11-26,AnnOpenP), [Test10255.hs:6:11]),
+((Test10255.hs:6:12-18,AnnRarrow), [Test10255.hs:6:20-21]),
 ((Test10255.hs:6:12-25,AnnRarrow), [Test10255.hs:6:20-21]),
 ((<no location info>,AnnEofPos), [Test10255.hs:8:1])
 ]
index dcaf80d..afac1f6 100644 (file)
@@ -33,6 +33,7 @@
 ((Test10278.hs:(8,20)-(10,57),AnnForall), [Test10278.hs:8:20-25]),
 ((Test10278.hs:(8,32)-(10,57),AnnDot), [Test10278.hs:8:43]),
 ((Test10278.hs:(8,32)-(10,57),AnnForall), [Test10278.hs:8:32-37]),
+((Test10278.hs:9:27-50,AnnRarrow), [Test10278.hs:10:31-32]),
 ((Test10278.hs:(9,27)-(10,57),AnnRarrow), [Test10278.hs:10:31-32]),
 ((Test10278.hs:9:38-50,AnnCloseP), [Test10278.hs:9:50]),
 ((Test10278.hs:9:38-50,AnnOpenP), [Test10278.hs:9:38]),
index c7b25a7..939a78e 100644 (file)
 ((Test10312.hs:68:28-35,AnnOpenP), [Test10312.hs:68:28]),
 ((Test10312.hs:68:28-35,AnnRarrow), [Test10312.hs:68:37-38]),
 ((Test10312.hs:68:28-51,AnnRarrow), [Test10312.hs:68:37-38]),
+((Test10312.hs:68:29,AnnRarrow), [Test10312.hs:68:31-32]),
 ((Test10312.hs:68:29-34,AnnRarrow), [Test10312.hs:68:31-32]),
 ((Test10312.hs:68:40-42,AnnCloseS), [Test10312.hs:68:42]),
 ((Test10312.hs:68:40-42,AnnOpenS), [Test10312.hs:68:40]),
index c50b5b9..24f1cf4 100644 (file)
 ((Test10399.hs:16:28-43,AnnDarrow), [Test10399.hs:16:45-46]),
 ((Test10399.hs:16:28-43,AnnOpenP), [Test10399.hs:16:28, Test10399.hs:16:28]),
 ((Test10399.hs:16:30-33,AnnComma), [Test10399.hs:16:34]),
+((Test10399.hs:16:48,AnnRarrow), [Test10399.hs:16:50-51]),
 ((Test10399.hs:(16,48)-(17,68),AnnRarrow), [Test10399.hs:16:50-51]),
+((Test10399.hs:16:53-66,AnnRarrow), [Test10399.hs:17:45-46]),
 ((Test10399.hs:(16,53)-(17,68),AnnRarrow), [Test10399.hs:17:45-46]),
+((Test10399.hs:17:48,AnnRarrow), [Test10399.hs:17:50-51]),
 ((Test10399.hs:17:48-68,AnnRarrow), [Test10399.hs:17:50-51]),
 ((Test10399.hs:17:66-68,AnnCloseS), [Test10399.hs:17:68]),
 ((Test10399.hs:17:66-68,AnnOpenS), [Test10399.hs:17:66]),
@@ -69,6 +72,7 @@
 ((Test10399.hs:18:20-54,AnnForall), [Test10399.hs:18:20-25]),
 ((Test10399.hs:18:31-36,AnnCloseP), [Test10399.hs:18:36]),
 ((Test10399.hs:18:31-36,AnnOpenP), [Test10399.hs:18:31]),
+((Test10399.hs:18:31-36,AnnRarrow), [Test10399.hs:18:38-39]),
 ((Test10399.hs:18:31-54,AnnRarrow), [Test10399.hs:18:38-39]),
 ((Test10399.hs:20:1-25,AnnCloseQ), [Test10399.hs:20:24-25]),
 ((Test10399.hs:20:1-25,AnnOpen), [Test10399.hs:20:1-3]),
index 78b7640..6c70c5c 100644 (file)
@@ -24,6 +24,7 @@
 ((Test11018.hs:12:21-32,AnnCloseP), [Test11018.hs:12:32]),
 ((Test11018.hs:12:21-32,AnnDcolonU), [Test11018.hs:12:24]),
 ((Test11018.hs:12:21-32,AnnOpenP), [Test11018.hs:12:21]),
+((Test11018.hs:12:26,AnnRarrow), [Test11018.hs:12:28-29]),
 ((Test11018.hs:12:26-31,AnnRarrow), [Test11018.hs:12:28-29]),
 ((Test11018.hs:(13,16)-(15,7),AnnCloseC), [Test11018.hs:15:7]),
 ((Test11018.hs:(13,16)-(15,7),AnnOpenC), [Test11018.hs:13:16]),
 ((Test11018.hs:37:22-32,AnnCloseP), [Test11018.hs:37:32]),
 ((Test11018.hs:37:22-32,AnnDcolonU), [Test11018.hs:37:25]),
 ((Test11018.hs:37:22-32,AnnOpenP), [Test11018.hs:37:22]),
+((Test11018.hs:37:27,AnnRarrowU), [Test11018.hs:37:29]),
 ((Test11018.hs:37:27-31,AnnRarrowU), [Test11018.hs:37:29]),
 ((Test11018.hs:(38,17)-(40,7),AnnCloseC), [Test11018.hs:40:7]),
 ((Test11018.hs:(38,17)-(40,7),AnnOpenC), [Test11018.hs:38:17]),
index 3c7a5af..2cdef95 100644 (file)
@@ -64,6 +64,7 @@
 ((AnnotationTuple.hs:18:1-28,AnnDcolon), [AnnotationTuple.hs:18:20-21]),
 ((AnnotationTuple.hs:18:1-28,AnnFamily), [AnnotationTuple.hs:18:6-11]),
 ((AnnotationTuple.hs:18:1-28,AnnSemi), [AnnotationTuple.hs:19:1]),
+((AnnotationTuple.hs:18:23,AnnRarrow), [AnnotationTuple.hs:18:25-26]),
 ((AnnotationTuple.hs:18:23-28,AnnRarrow), [AnnotationTuple.hs:18:25-26]),
 ((AnnotationTuple.hs:(20,1)-(24,14),AnnFunId), [AnnotationTuple.hs:20:1-5]),
 ((AnnotationTuple.hs:(20,1)-(24,14),AnnSemi), [AnnotationTuple.hs:25:1]),
index e229ba6..092ba97 100644 (file)
 
 (AK AnnotationTuple.hs:18:1-28 AnnSemi = [AnnotationTuple.hs:19:1])
 
+(AK AnnotationTuple.hs:18:23 AnnRarrow = [AnnotationTuple.hs:18:25-26])
+
 (AK AnnotationTuple.hs:18:23-28 AnnRarrow = [AnnotationTuple.hs:18:25-26])
 
 (AK AnnotationTuple.hs:(20,1)-(24,14) AnnFunId = [AnnotationTuple.hs:20:1-5])