The production for squals is incorrect; see D806 for specifics.
authorAlan Zimmerman <alan.zimm@gmail.com>
Tue, 7 Apr 2015 14:10:27 +0000 (09:10 -0500)
committerAustin Seipp <austin@well-typed.com>
Tue, 7 Apr 2015 14:13:38 +0000 (09:13 -0500)
This diff depends on D803.

Reviewed By: austin

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

GHC Trac Issues: #10214

12 files changed:
compiler/parser/Parser.y
testsuite/tests/ghc-api/annotations/ListComprehensions.hs
testsuite/tests/ghc-api/annotations/Makefile
testsuite/tests/ghc-api/annotations/listcomps.stdout
testsuite/tests/parser/should_fail/readFail042.stderr
testsuite/tests/parser/should_fail/readFail043.stderr
testsuite/tests/typecheck/should_fail/mc19.stderr
testsuite/tests/typecheck/should_fail/mc21.stderr
testsuite/tests/typecheck/should_fail/mc22.stderr
testsuite/tests/typecheck/should_fail/mc25.stderr
testsuite/tests/typecheck/should_fail/tcfail191.stderr
testsuite/tests/typecheck/should_fail/tcfail193.stderr

index 99c5374..de93796 100644 (file)
@@ -2473,11 +2473,13 @@ squals :: { Located [LStmt RdrName (LHsExpr RdrName)] }   -- In reverse order, b
                                         -- one can "grab" the earlier ones
     : squals ',' transformqual
              {% addAnnotation (gl $ last $ unLoc $1) AnnComma (gl $2) >>
-                return (sLL $1 $> [L (getLoc $3) ((unLoc $3) (reverse (unLoc $1)))]) }
+                ams (sLL $1 $> ()) (fst $ unLoc $3) >>
+                return (sLL $1 $> [sLL $1 $> ((snd $ unLoc $3) (reverse (unLoc $1)))]) }
     | squals ',' qual
              {% addAnnotation (gl $ head $ unLoc $1) AnnComma (gl $2) >>
                 return (sLL $1 $> ($3 : unLoc $1)) }
-    | transformqual                       { sLL $1 $> [L (getLoc $1) ((unLoc $1) [])] }
+    | transformqual        {% ams $1 (fst $ unLoc $1) >>
+                              return (sLL $1 $> [L (getLoc $1) ((snd $ unLoc $1) [])]) }
     | qual                                { sL1 $1 [$1] }
 --  | transformquals1 ',' '{|' pquals '|}'   { sLL $1 $> ($4 : unLoc $1) }
 --  | '{|' pquals '|}'                       { sL1 $1 [$2] }
@@ -2487,19 +2489,15 @@ squals :: { Located [LStmt RdrName (LHsExpr RdrName)] }   -- In reverse order, b
 -- consensus on the syntax, this feature is not being used until we
 -- get user demand.
 
-transformqual :: { Located ([LStmt RdrName (LHsExpr RdrName)] -> Stmt RdrName (LHsExpr RdrName)) }
+transformqual :: { Located ([AddAnn],[LStmt RdrName (LHsExpr RdrName)] -> Stmt RdrName (LHsExpr RdrName)) }
                         -- Function is applied to a list of stmts *in order*
-    : 'then' exp               {% ams (sLL $1 $> $ \ss -> (mkTransformStmt ss $2))
-                                      [mj AnnThen $1] }
-    | 'then' exp 'by' exp      {% ams (sLL $1 $> $ \ss -> (mkTransformByStmt ss $2 $4))
-                                      [mj AnnThen $1,mj AnnBy  $3] }
+    : 'then' exp               { sLL $1 $> ([mj AnnThen $1], \ss -> (mkTransformStmt ss $2)) }
+    | 'then' exp 'by' exp      { sLL $1 $> ([mj AnnThen $1,mj AnnBy  $3],\ss -> (mkTransformByStmt ss $2 $4)) }
     | 'then' 'group' 'using' exp
-             {% ams (sLL $1 $> $ \ss -> (mkGroupUsingStmt ss $4))
-                    [mj AnnThen $1,mj AnnGroup $2,mj AnnUsing $3] }
+             { sLL $1 $> ([mj AnnThen $1,mj AnnGroup $2,mj AnnUsing $3], \ss -> (mkGroupUsingStmt ss $4)) }
 
     | 'then' 'group' 'by' exp 'using' exp
-             {% ams (sLL $1 $> $ \ss -> (mkGroupByUsingStmt ss $4 $6))
-                     [mj AnnThen $1,mj AnnGroup $2,mj AnnBy $3,mj AnnUsing $5] }
+             { sLL $1 $> ([mj AnnThen $1,mj AnnGroup $2,mj AnnBy $3,mj AnnUsing $5], \ss -> (mkGroupByUsingStmt ss $4 $6)) }
 
 -- Note that 'group' is a special_id, which means that you can enable
 -- TransformListComp while still using Data.List.group. However, this
index c61f7ca..0738da5 100644 (file)
@@ -20,3 +20,9 @@ parallelListComp = [ x + y * z
                    | y <- [10..20]
                    | z <- [20..30]
                    ]
+
+oldest :: [Int] -> [String]
+oldest tbl = [ "str"
+             | n <- tbl
+             , then id
+             ]
index 5d10d7f..383fb26 100644 (file)
@@ -31,4 +31,4 @@ listcomps:
        '$(TEST_HC)' $(TEST_HC_OPTS) --make -v0 -package ghc listcomps
        ./listcomps "`'$(TEST_HC)' $(TEST_HC_OPTS) --print-libdir | tr -d '\r'`"
 
-.PHONY: clean annotations parseTree comments exampleTest listcops
+.PHONY: clean annotations parseTree comments exampleTest listcomps
index cf70772..081258a 100644 (file)
  ListComprehensions.hs:20:28-29, ListComprehensions.hs:20:32-33,
  ListComprehensions.hs:21:22, ListComprehensions.hs:21:22-34,
  ListComprehensions.hs:21:27-34, ListComprehensions.hs:21:28-29,
- ListComprehensions.hs:21:32-33, <no location info>}
+ ListComprehensions.hs:21:32-33, ListComprehensions.hs:24:1-6,
+ ListComprehensions.hs:24:1-27, ListComprehensions.hs:24:11-15,
+ ListComprehensions.hs:24:11-27, ListComprehensions.hs:24:12-14,
+ ListComprehensions.hs:24:20-27, ListComprehensions.hs:24:21-26,
+ ListComprehensions.hs:25:1-6, ListComprehensions.hs:(25,1)-(28,14),
+ ListComprehensions.hs:25:8-10,
+ ListComprehensions.hs:(25,12)-(28,14),
+ ListComprehensions.hs:(25,14)-(28,14),
+ ListComprehensions.hs:25:16-20, ListComprehensions.hs:26:16,
+ ListComprehensions.hs:26:16-23,
+ ListComprehensions.hs:(26,16)-(27,22),
+ ListComprehensions.hs:26:21-23, ListComprehensions.hs:27:21-22,
+ <no location info>}
 --------------------------------
 [
 (AK ListComprehensions.hs:1:1 AnnModule = [ListComprehensions.hs:6:1-6])
@@ -71,7 +83,7 @@
 
 (AK ListComprehensions.hs:(18,1)-(22,20) AnnFunId = [ListComprehensions.hs:18:1-16])
 
-(AK ListComprehensions.hs:(18,1)-(22,20) AnnSemi = [ListComprehensions.hs:23:1])
+(AK ListComprehensions.hs:(18,1)-(22,20) AnnSemi = [ListComprehensions.hs:24:1])
 
 (AK ListComprehensions.hs:(18,20)-(22,20) AnnCloseS = [ListComprehensions.hs:22:20])
 
 
 (AK ListComprehensions.hs:21:27-34 AnnOpenS = [ListComprehensions.hs:21:27])
 
-(AK <no location info> AnnEofPos = [ListComprehensions.hs:23:1])
+(AK ListComprehensions.hs:24:1-27 AnnDcolon = [ListComprehensions.hs:24:8-9])
+
+(AK ListComprehensions.hs:24:1-27 AnnSemi = [ListComprehensions.hs:25:1])
+
+(AK ListComprehensions.hs:24:11-15 AnnCloseS = [ListComprehensions.hs:24:15])
+
+(AK ListComprehensions.hs:24:11-15 AnnOpenS = [ListComprehensions.hs:24:11])
+
+(AK ListComprehensions.hs:24:11-27 AnnRarrow = [ListComprehensions.hs:24:17-18])
+
+(AK ListComprehensions.hs:24:20-27 AnnCloseS = [ListComprehensions.hs:24:27])
+
+(AK ListComprehensions.hs:24:20-27 AnnOpenS = [ListComprehensions.hs:24:20])
+
+(AK ListComprehensions.hs:(25,1)-(28,14) AnnEqual = [ListComprehensions.hs:25:12])
+
+(AK ListComprehensions.hs:(25,1)-(28,14) AnnFunId = [ListComprehensions.hs:25:1-6])
+
+(AK ListComprehensions.hs:(25,1)-(28,14) AnnSemi = [ListComprehensions.hs:29:1])
+
+(AK ListComprehensions.hs:(25,14)-(28,14) AnnCloseS = [ListComprehensions.hs:28:14])
+
+(AK ListComprehensions.hs:(25,14)-(28,14) AnnOpenS = [ListComprehensions.hs:25:14])
+
+(AK ListComprehensions.hs:(25,14)-(28,14) AnnVbar = [ListComprehensions.hs:26:14])
+
+(AK ListComprehensions.hs:26:16-23 AnnComma = [ListComprehensions.hs:27:14])
+
+(AK ListComprehensions.hs:26:16-23 AnnLarrow = [ListComprehensions.hs:26:18-19])
+
+(AK ListComprehensions.hs:(26,16)-(27,22) AnnThen = [ListComprehensions.hs:27:16-19])
+
+(AK <no location info> AnnEofPos = [ListComprehensions.hs:29:1])
 ]
 
index b5d64f8..06c3b03 100644 (file)
@@ -1,9 +1,9 @@
 
-readFail042.hs:10:9:
+readFail042.hs:9:9:
     Unexpected transform statement in a list comprehension
     Use TransformListComp
 
-readFail042.hs:11:9:
+readFail042.hs:9:9:
     Unexpected transform statement in a list comprehension
     Use TransformListComp
 
index bdbacb7..8d29793 100644 (file)
@@ -1,5 +1,13 @@
 
-readFail043.hs:10:9:
+readFail043.hs:9:9:
+    Unexpected transform statement in a list comprehension
+    Use TransformListComp
+
+readFail043.hs:9:9:
+    Unexpected transform statement in a list comprehension
+    Use TransformListComp
+
+readFail043.hs:9:9:
     Unexpected transform statement in a list comprehension
     Use TransformListComp
 
@@ -9,18 +17,10 @@ readFail043.hs:10:23: Not in scope: ‘x’
 
 readFail043.hs:10:25: Not in scope: ‘using’
 
-readFail043.hs:11:9:
-    Unexpected transform statement in a list comprehension
-    Use TransformListComp
-
 readFail043.hs:11:20: Not in scope: ‘by’
 
 readFail043.hs:11:23: Not in scope: ‘x’
 
 readFail043.hs:11:25: Not in scope: ‘using’
 
-readFail043.hs:12:9:
-    Unexpected transform statement in a list comprehension
-    Use TransformListComp
-
 readFail043.hs:12:20: Not in scope: ‘using’
index d7181ad..f8ca03f 100644 (file)
@@ -2,7 +2,7 @@
 mc19.hs:10:31:
     Couldn't match type ‘a’ with ‘[a]’
       ‘a’ is a rigid type variable bound by
-          a type expected by the context: [a] -> [a] at mc19.hs:10:26
+          a type expected by the context: [a] -> [a] at mc19.hs:10:10
     Expected type: [a] -> [a]
       Actual type: [a] -> [[a]]
     In the expression: inits
index 0e72729..9505065 100644 (file)
@@ -2,7 +2,7 @@
 mc21.hs:12:26:
     Couldn't match type ‘a’ with ‘[a]’
       ‘a’ is a rigid type variable bound by
-          a type expected by the context: [a] -> [[a]] at mc21.hs:12:9
+          a type expected by the context: [a] -> [[a]] at mc21.hs:11:9
     Expected type: [a] -> [[a]]
       Actual type: [[a]] -> [[a]]
     In the expression: take 5
index 785bf07..9501f93 100644 (file)
@@ -1,5 +1,5 @@
 \r
-mc22.hs:10:9:\r
+mc22.hs:9:9:\r
     No instance for (Functor t) arising from a use of ‘fmap’\r
     Possible fix:\r
       add (Functor t) to the context of\r
@@ -13,7 +13,7 @@ mc22.hs:10:9:
 mc22.hs:10:26:\r
     Couldn't match type ‘a’ with ‘t a’\r
       ‘a’ is a rigid type variable bound by\r
-          a type expected by the context: [a] -> [t a] at mc22.hs:10:9\r
+          a type expected by the context: [a] -> [t a] at mc22.hs:9:9\r
     Expected type: [a] -> [t a]\r
       Actual type: [t a] -> [t a]\r
     Relevant bindings include foo :: [t [Char]] (bound at mc22.hs:8:1)\r
index fb136bc..83fe130 100644 (file)
@@ -1,5 +1,5 @@
 
-mc25.hs:9:24:
+mc25.hs:9:10:
     No instance for (Functor t1) arising from a use of ‘fmap’
     Possible fix:
       add (Functor t1) to the context of
index 2158927..d923744 100644 (file)
@@ -2,7 +2,7 @@
 tcfail191.hs:11:26:
     Couldn't match type ‘a’ with ‘[a]’
       ‘a’ is a rigid type variable bound by
-          a type expected by the context: [a] -> [[a]] at tcfail191.hs:11:9
+          a type expected by the context: [a] -> [[a]] at tcfail191.hs:10:9
     Expected type: [a] -> [[a]]
       Actual type: [[a]] -> [[a]]
     In the expression: take 5
index 6cbf6d8..d2f3f26 100644 (file)
@@ -2,7 +2,7 @@
 tcfail193.hs:10:31:
     Couldn't match type ‘a’ with ‘[a]’
       ‘a’ is a rigid type variable bound by
-          a type expected by the context: [a] -> [a] at tcfail193.hs:10:26
+          a type expected by the context: [a] -> [a] at tcfail193.hs:10:10
     Expected type: [a] -> [a]
       Actual type: [a] -> [[a]]
     In the expression: inits