summaryrefslogtreecommitdiff
path: root/compiler
diff options
context:
space:
mode:
authorAlan Zimmerman <alan.zimm@gmail.com>2022-03-10 23:23:16 +0000
committerMarge Bot <ben+marge-bot@smart-cactus.org>2022-05-11 08:23:33 -0400
commit4a4c77ed8f16f157dd647593de58840b024bbd2d (patch)
treeca61146523ef92158c599d9693bd9583c08e6146 /compiler
parent8500206ea7084f3914efd3fe7f4336f2893eb4ac (diff)
downloadhaskell-4a4c77ed8f16f157dd647593de58840b024bbd2d.tar.gz
EPA: do statement with leading semicolon has wrong anchor
The code do; a <- doAsync; b Generated an incorrect Anchor for the statement list that starts after the first semicolon. This commit fixes it. Closes #20256
Diffstat (limited to 'compiler')
-rw-r--r--compiler/GHC/Parser.y6
-rw-r--r--compiler/GHC/Parser/PostProcess.hs13
2 files changed, 16 insertions, 3 deletions
diff --git a/compiler/GHC/Parser.y b/compiler/GHC/Parser.y
index 01c0459866..bb57f39d7b 100644
--- a/compiler/GHC/Parser.y
+++ b/compiler/GHC/Parser.y
@@ -3318,10 +3318,10 @@ apats :: { [LPat GhcPs] }
-- Statement sequences
stmtlist :: { forall b. DisambECP b => PV (LocatedL [LocatedA (Stmt GhcPs (LocatedA b))]) }
- : '{' stmts '}' { $2 >>= \ $2 -> amsrl
- (sLL $1 $> (reverse $ snd $ unLoc $2)) (AnnList (Just $ glR $2) (Just $ moc $1) (Just $ mcc $3) (fromOL $ fst $ unLoc $2) []) }
+ : '{' stmts '}' { $2 >>= \ $2 ->
+ amsrl (sLL $1 $> (reverse $ snd $ unLoc $2)) (AnnList (Just $ stmtsAnchor $2) (Just $ moc $1) (Just $ mcc $3) (fromOL $ fst $ unLoc $2) []) }
| vocurly stmts close { $2 >>= \ $2 -> amsrl
- (L (gl $2) (reverse $ snd $ unLoc $2)) (AnnList (Just $ glR $2) Nothing Nothing (fromOL $ fst $ unLoc $2) []) }
+ (L (stmtsLoc $2) (reverse $ snd $ unLoc $2)) (AnnList (Just $ stmtsAnchor $2) Nothing Nothing (fromOL $ fst $ unLoc $2) []) }
-- do { ;; s ; s ; ; s ;; }
-- The last Stmt should be an expression, but that's hard to enforce
diff --git a/compiler/GHC/Parser/PostProcess.hs b/compiler/GHC/Parser/PostProcess.hs
index 8a89bef84d..845f7eb25c 100644
--- a/compiler/GHC/Parser/PostProcess.hs
+++ b/compiler/GHC/Parser/PostProcess.hs
@@ -39,6 +39,7 @@ module GHC.Parser.PostProcess (
fromSpecTyVarBndr, fromSpecTyVarBndrs,
annBinds,
fixValbindsAnn,
+ stmtsAnchor, stmtsLoc,
cvBindGroup,
cvBindsAndSigs,
@@ -478,6 +479,18 @@ fixValbindsAnn EpAnnNotUsed = EpAnnNotUsed
fixValbindsAnn (EpAnn anchor (AnnList ma o c r t) cs)
= (EpAnn (widenAnchor anchor (map trailingAnnToAddEpAnn t)) (AnnList ma o c r t) cs)
+-- | The 'Anchor' for a stmtlist is based on either the location or
+-- the first semicolon annotion.
+stmtsAnchor :: Located (OrdList AddEpAnn,a) -> Anchor
+stmtsAnchor (L l ((ConsOL (AddEpAnn _ (EpaSpan r)) _), _))
+ = widenAnchorR (Anchor (realSrcSpan l) UnchangedAnchor) r
+stmtsAnchor (L l _) = Anchor (realSrcSpan l) UnchangedAnchor
+
+stmtsLoc :: Located (OrdList AddEpAnn,a) -> SrcSpan
+stmtsLoc (L l ((ConsOL aa _), _))
+ = widenSpan l [aa]
+stmtsLoc (L l _) = l
+
{- **********************************************************************
#cvBinds-etc# Converting to @HsBinds@, etc.