diff options
author | Alan Zimmerman <alan.zimm@gmail.com> | 2021-08-22 21:14:46 +0100 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2021-09-06 22:57:55 -0400 |
commit | 407d3b3a3a219dab56d0a36598c637aa45da61e1 (patch) | |
tree | 4e03381c68302e2a995c573b4b57a4250f12dbf5 /utils/check-exact/ExactPrint.hs | |
parent | 5b41353355022c1247e0516d541b7f7fb49f0e29 (diff) | |
download | haskell-407d3b3a3a219dab56d0a36598c637aa45da61e1.tar.gz |
EPA: order of semicolons and comments for top-level decls is wrong
A comment followed by a semicolon at the top level resulted in the
preceding comments being attached to the following declaration.
Capture the comments as belonging to the declaration preceding the
semicolon instead.
Closes #20258
Diffstat (limited to 'utils/check-exact/ExactPrint.hs')
-rw-r--r-- | utils/check-exact/ExactPrint.hs | 28 |
1 files changed, 19 insertions, 9 deletions
diff --git a/utils/check-exact/ExactPrint.hs b/utils/check-exact/ExactPrint.hs index 74135cb9f6..fc04e24332 100644 --- a/utils/check-exact/ExactPrint.hs +++ b/utils/check-exact/ExactPrint.hs @@ -268,15 +268,31 @@ enterAnn (Entry anchor' cs) a = do withOffset st (advance edp >> exact a) when ((getFollowingComments cs) /= []) $ do - -- debugM $ "starting trailing comments:" ++ showAst (getFollowingComments cs) + debugM $ "starting trailing comments:" ++ showAst (getFollowingComments cs) mapM_ printOneComment (map tokComment $ getFollowingComments cs) - -- debugM $ "ending trailing comments" + debugM $ "ending trailing comments" -- --------------------------------------------------------------------- addCommentsA :: [LEpaComment] -> EPP () addCommentsA csNew = addComments (map tokComment csNew) +{- +TODO: When we addComments, some may have an anchor that is no longer +valid, as it has been moved and has an anchor_op. + +Does an Anchor even make sense for a comment, perhaps it should be an +EpaLocation? + +How do we sort them? do we assign a location based on when we add them +to the list, based on the current output pos? Except the offset is a +delta compared to a reference location. Need to nail the concept of +the reference location. + +By definition it is the current anchor, so work against that. And that +also means that the first entry comment that has moved should not have +a line offset. +-} addComments :: [Comment] -> EPP () addComments csNew = do debugM $ "addComments:" ++ show csNew @@ -1188,12 +1204,6 @@ instance (ExactPrint tm, ExactPrint ty, Outputable tm, Outputable ty) -- --------------------------------------------------------------------- --- instance ExactPrint [LHsTyVarBndr () GhcPs] where --- getAnnotationEntry = const NoEntryVal --- exact bs = mapM_ markAnnotated bs - --- --------------------------------------------------------------------- - instance ExactPrint (ClsInstDecl GhcPs) where getAnnotationEntry cid = fromAnn (fst $ cid_ext cid) @@ -3911,7 +3921,7 @@ printString layout str = do cr = getDeltaLine strDP p <- getPosP colOffset <- getLayoutOffsetP - debugM $ "printString:(p,colOffset,strDP,cr)=" ++ show (p,colOffset,strDP,cr) + -- debugM $ "printString:(p,colOffset,strDP,cr)=" ++ show (p,colOffset,strDP,cr) if cr == 0 then setPosP (undelta p strDP colOffset) else setPosP (undelta p strDP 1) |