Parser: commas_tup_tail duplicate SrcSpan on "Missing" value
authorAlan Zimmerman <alan.zimm@gmail.com>
Thu, 18 Jun 2015 14:19:50 +0000 (16:19 +0200)
committerAlan Zimmerman <alan.zimm@gmail.com>
Thu, 18 Jun 2015 14:19:50 +0000 (16:19 +0200)
Summary:
Parsing

    {-# LANGUAGE TupleSections #-}

    baz = (1, "hello", 6.5,,) 'a' (Just ())

Results in the following AST fragment

    (L tests/examples/Tuple.hs:3:7-25
       (ExplicitTuple
          [ L tests/examples/Tuple.hs:3:8
              (Present
                 (L tests/examples/Tuple.hs:3:8
                    (HsOverLit
                       (OverLit
                          (HsIntegral [ '1' ] 1)
                          PlaceHolder
                          (HsLit
                             (HsString
                                []
                                {abstract:FastString}))
                          PlaceHolder))))
          , L tests/examples/Tuple.hs:3:11-17
              (Present
                 (L tests/examples/Tuple.hs:3:11-17
                    (HsLit
                       (HsString
                          [ '"'
                          , 'h'
                          , 'e'
                          , 'l'
                          , 'l'
                          , 'o'
                          , '"'
                          ]
                          {abstract:FastString}))))
          , L tests/examples/Tuple.hs:3:20-22
              (Present
                 (L tests/examples/Tuple.hs:3:20-22
                    (HsOverLit
                       (OverLit
                          (HsFractional
                             (FL
                                [ '6' , '.' , '5' ]
                                (:% 13 2)))
                          PlaceHolder
                          (HsLit
                             (HsString
                                []
                                {abstract:FastString}))
                          PlaceHolder))))
          , L tests/examples/Tuple.hs:3:24
              (Missing PlaceHolder)
          , L tests/examples/Tuple.hs:3:24
              (Missing PlaceHolder)
          ]

The final `Missing PlaceHolder` has a duplicated `SrcSpan`

Test Plan: ./validate

Reviewers: austin, hvr, bgamari

Reviewed By: bgamari

Subscribers: thomie, bgamari, mpickering

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

GHC Trac Issues: #10537

compiler/parser/Parser.y
testsuite/tests/ghc-api/annotations/exampleTest.stdout
testsuite/tests/ghc-api/annotations/parseTree.stdout

index 682b342..5414735 100644 (file)
@@ -2386,28 +2386,22 @@ tup_exprs :: { [LHsTupArg RdrName] }
            | commas tup_tail
                 {% do { mapM_ (\ll -> addAnnotation ll AnnComma ll) (fst $1)
                       ; return
-                           (let tt = if null $2
-                                       then [noLoc missingTupArg]
-                                       else $2
-                            in map (\l -> L l missingTupArg) (fst $1) ++ tt) } }
+                           (map (\l -> L l missingTupArg) (fst $1) ++ $2) } }
 
 -- Always starts with commas; always follows an expr
 commas_tup_tail :: { (SrcSpan,[LHsTupArg RdrName]) }
 commas_tup_tail : commas tup_tail
        {% do { mapM_ (\ll -> addAnnotation ll AnnComma ll) (tail $ fst $1)
              ; return (
-         let tt = if null $2
-                    then [L (last $ fst $1) missingTupArg]
-                    else $2
-         in (head $ fst $1
-            ,(map (\l -> L l missingTupArg) (tail $ fst $1)) ++ tt)) } }
+            (head $ fst $1
+            ,(map (\l -> L l missingTupArg) (tail $ fst $1)) ++ $2)) } }
 
 -- Always follows a comma
 tup_tail :: { [LHsTupArg RdrName] }
           : texp commas_tup_tail {% addAnnotation (gl $1) AnnComma (fst $2) >>
                                     return ((L (gl $1) (Present $1)) : snd $2) }
           | texp                 { [L (gl $1) (Present $1)] }
-          | {- empty -}          { [] {- [noLoc missingTupArg] -} }
+          | {- empty -}          { [noLoc missingTupArg] }
 
 -----------------------------------------------------------------------------
 -- List expressions
index cd6f9c0..210a4d8 100644 (file)
@@ -1,10 +1,9 @@
 ---Problems---------------------
 [
-(AK <no location info> AnnEofPos = [AnnotationTuple.hs:32:1])
 ]
 
 ---Problems'--------------------
-[(AnnEofPos, AnnotationTuple.hs:32:1)]
+[]
 --------------------------------
 [
 (AK AnnotationTuple.hs:1:1 AnnCloseC = [AnnotationTuple.hs:27:1])
index f7d1e5d..7d651aa 100644 (file)
@@ -8,8 +8,7 @@
  (AnnotationTuple.hs:16:20-22, [p], (6.5)),
  (AnnotationTuple.hs:16:24, [m], ()),
  (AnnotationTuple.hs:16:25, [m], ()),
- (AnnotationTuple.hs:16:26, [m], ()),
- (AnnotationTuple.hs:16:26, [m], ())]
+ (AnnotationTuple.hs:16:26, [m], ()), (<no location info>, [m], ())]
 [
 (AK AnnotationTuple.hs:1:1 AnnCloseC = [AnnotationTuple.hs:27:1])