diff options
author | Alan Zimmerman <alan.zimm@gmail.com> | 2022-12-29 22:12:27 +0000 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2023-01-05 10:49:09 -0500 |
commit | 22bb89989fc0a907ef6b8f6ae99aa8907f67e438 (patch) | |
tree | 017ae9669e6ab88c329028514faa3e94fd78509c /testsuite/tests | |
parent | 541aedcd9023445b8e914d595ae8dcf2e799d618 (diff) | |
download | haskell-22bb89989fc0a907ef6b8f6ae99aa8907f67e438.tar.gz |
EPA: Do not collect comments from end of file
In Parser.y semis1 production triggers for the virtual semi at the end
of the file. This is detected by it being zero length.
In this case, do not extend the span being used to gather comments, so
any final comments are allocated at the module level instead.
Diffstat (limited to 'testsuite/tests')
8 files changed, 188 insertions, 47 deletions
diff --git a/testsuite/tests/ghc-api/exactprint/RmDecl4.expected.hs b/testsuite/tests/ghc-api/exactprint/RmDecl4.expected.hs index 9a36673062..e7c71dbd08 100644 --- a/testsuite/tests/ghc-api/exactprint/RmDecl4.expected.hs +++ b/testsuite/tests/ghc-api/exactprint/RmDecl4.expected.hs @@ -7,5 +7,4 @@ ff y = y + zz + xx zz = 1 - -- EOF diff --git a/testsuite/tests/ghc-api/exactprint/Test20239.stderr b/testsuite/tests/ghc-api/exactprint/Test20239.stderr index 8bfb5085ce..b89a29fbf2 100644 --- a/testsuite/tests/ghc-api/exactprint/Test20239.stderr +++ b/testsuite/tests/ghc-api/exactprint/Test20239.stderr @@ -24,7 +24,14 @@ { Test20239.hs:7:34-63 }))) (EpaCommentsBalanced [] - [])) + [(L + (Anchor + { Test20239.hs:7:34-63 } + (UnchangedAnchor)) + (EpaComment + (EpaLineComment + "-- ^ Run any arbitrary IO code") + { Test20239.hs:6:86 }))])) (VirtualBraces (1)) (Nothing) @@ -50,15 +57,7 @@ (EpaComment (EpaLineComment "-- | Leading Haddock Comment") - { Test20239.hs:1:18-22 })) - ,(L - (Anchor - { Test20239.hs:7:34-63 } - (UnchangedAnchor)) - (EpaComment - (EpaLineComment - "-- ^ Run any arbitrary IO code") - { Test20239.hs:6:86 }))])) { Test20239.hs:(4,1)-(6,86) }) + { Test20239.hs:1:18-22 }))])) { Test20239.hs:(4,1)-(6,86) }) (InstD (NoExtField) (DataFamInstD diff --git a/testsuite/tests/ghc-api/exactprint/ZeroWidthSemi.hs b/testsuite/tests/ghc-api/exactprint/ZeroWidthSemi.hs new file mode 100644 index 0000000000..6c3de63737 --- /dev/null +++ b/testsuite/tests/ghc-api/exactprint/ZeroWidthSemi.hs @@ -0,0 +1,8 @@ +module ZeroWidthSemi where + +-- leading comments + +-- Function comment +a = 0 + +-- Trailing comment, should be in HsModule extension point diff --git a/testsuite/tests/ghc-api/exactprint/ZeroWidthSemi.stderr b/testsuite/tests/ghc-api/exactprint/ZeroWidthSemi.stderr new file mode 100644 index 0000000000..13937cd36b --- /dev/null +++ b/testsuite/tests/ghc-api/exactprint/ZeroWidthSemi.stderr @@ -0,0 +1,134 @@ + +==================== Parser AST ==================== + +(L + { ZeroWidthSemi.hs:1:1 } + (HsModule + (XModulePs + (EpAnn + (Anchor + { ZeroWidthSemi.hs:1:1 } + (UnchangedAnchor)) + (AnnsModule + [(AddEpAnn AnnModule (EpaSpan { ZeroWidthSemi.hs:1:1-6 })) + ,(AddEpAnn AnnWhere (EpaSpan { ZeroWidthSemi.hs:1:22-26 }))] + (AnnList + (Nothing) + (Nothing) + (Nothing) + [] + []) + (Just + ((,) + { ZeroWidthSemi.hs:9:1 } + { ZeroWidthSemi.hs:8:1-58 }))) + (EpaCommentsBalanced + [(L + (Anchor + { ZeroWidthSemi.hs:3:1-19 } + (UnchangedAnchor)) + (EpaComment + (EpaLineComment + "-- leading comments") + { ZeroWidthSemi.hs:1:22-26 }))] + [(L + (Anchor + { ZeroWidthSemi.hs:8:1-58 } + (UnchangedAnchor)) + (EpaComment + (EpaLineComment + "-- Trailing comment, should be in HsModule extension point") + { ZeroWidthSemi.hs:6:5 }))])) + (VirtualBraces + (1)) + (Nothing) + (Nothing)) + (Just + (L + (SrcSpanAnn (EpAnnNotUsed) { ZeroWidthSemi.hs:1:8-20 }) + {ModuleName: ZeroWidthSemi})) + (Nothing) + [] + [(L + (SrcSpanAnn (EpAnn + (Anchor + { ZeroWidthSemi.hs:6:1-5 } + (UnchangedAnchor)) + (AnnListItem + []) + (EpaComments + [(L + (Anchor + { ZeroWidthSemi.hs:5:1-19 } + (UnchangedAnchor)) + (EpaComment + (EpaLineComment + "-- Function comment") + { ZeroWidthSemi.hs:3:1-19 }))])) { ZeroWidthSemi.hs:6:1-5 }) + (ValD + (NoExtField) + (FunBind + (NoExtField) + (L + (SrcSpanAnn (EpAnnNotUsed) { ZeroWidthSemi.hs:6:1 }) + (Unqual + {OccName: a})) + (MG + (FromSource) + (L + (SrcSpanAnn (EpAnnNotUsed) { ZeroWidthSemi.hs:6:1-5 }) + [(L + (SrcSpanAnn (EpAnnNotUsed) { ZeroWidthSemi.hs:6:1-5 }) + (Match + (EpAnn + (Anchor + { ZeroWidthSemi.hs:6:1-5 } + (UnchangedAnchor)) + [] + (EpaComments + [])) + (FunRhs + (L + (SrcSpanAnn (EpAnnNotUsed) { ZeroWidthSemi.hs:6:1 }) + (Unqual + {OccName: a})) + (Prefix) + (NoSrcStrict)) + [] + (GRHSs + (EpaComments + []) + [(L + (SrcSpanAnn + (EpAnnNotUsed) + { ZeroWidthSemi.hs:6:3-5 }) + (GRHS + (EpAnn + (Anchor + { ZeroWidthSemi.hs:6:3-5 } + (UnchangedAnchor)) + (GrhsAnn + (Nothing) + (AddEpAnn AnnEqual (EpaSpan { ZeroWidthSemi.hs:6:3 }))) + (EpaComments + [])) + [] + (L + (SrcSpanAnn (EpAnnNotUsed) { ZeroWidthSemi.hs:6:5 }) + (HsOverLit + (EpAnn + (Anchor + { ZeroWidthSemi.hs:6:5 } + (UnchangedAnchor)) + (NoEpAnns) + (EpaComments + [])) + (OverLit + (NoExtField) + (HsIntegral + (IL + (SourceText 0) + (False) + (0))))))))] + (EmptyLocalBinds + (NoExtField)))))])))))])) diff --git a/testsuite/tests/ghc-api/exactprint/all.T b/testsuite/tests/ghc-api/exactprint/all.T index 97d94b566c..825d57c339 100644 --- a/testsuite/tests/ghc-api/exactprint/all.T +++ b/testsuite/tests/ghc-api/exactprint/all.T @@ -37,3 +37,4 @@ test('RmTypeSig2', ignore_stderr, makefile_test, ['RmTypeSig2']) test('AddHiding1', ignore_stderr, makefile_test, ['AddHiding1']) test('AddHiding2', ignore_stderr, makefile_test, ['AddHiding2']) test('Test20239', normal, compile_fail, ['-dsuppress-uniques -ddump-parsed-ast -dkeep-comments']) +test('ZeroWidthSemi', normal, compile, ['-dsuppress-uniques -ddump-parsed-ast -dkeep-comments']) diff --git a/testsuite/tests/parser/should_compile/DumpParsedAstComments.stderr b/testsuite/tests/parser/should_compile/DumpParsedAstComments.stderr index 6050639d73..4eb1a179db 100644 --- a/testsuite/tests/parser/should_compile/DumpParsedAstComments.stderr +++ b/testsuite/tests/parser/should_compile/DumpParsedAstComments.stderr @@ -82,15 +82,7 @@ (EpaComment (EpaLineComment "-- comment 2 for foo") - { DumpParsedAstComments.hs:9:1-20 })) - ,(L - (Anchor - { DumpParsedAstComments.hs:15:1-20 } - (UnchangedAnchor)) - (EpaComment - (EpaLineComment - "-- | Haddock comment") - { DumpParsedAstComments.hs:13:3 + { DumpParsedAstComments.hs:9:1-20 }))])) { DumpParsedAstComments.hs:(11,1)-(13,3) }) (ValD (NoExtField) @@ -219,7 +211,15 @@ (AnnListItem []) (EpaComments - [])) { DumpParsedAstComments.hs:16:1-23 }) + [(L + (Anchor + { DumpParsedAstComments.hs:15:1-20 } + (UnchangedAnchor)) + (EpaComment + (EpaLineComment + "-- | Haddock comment") + { DumpParsedAstComments.hs:13:3 + }))])) { DumpParsedAstComments.hs:16:1-23 }) (ValD (NoExtField) (FunBind diff --git a/testsuite/tests/parser/should_compile/T20718.stderr b/testsuite/tests/parser/should_compile/T20718.stderr index bd071a0227..16eeaa4e69 100644 --- a/testsuite/tests/parser/should_compile/T20718.stderr +++ b/testsuite/tests/parser/should_compile/T20718.stderr @@ -55,7 +55,22 @@ (EpaLineComment "-- before 2") { T20718.hs:5:1-11 }))] - [])) + [(L + (Anchor + { T20718.hs:10:1-8 } + (UnchangedAnchor)) + (EpaComment + (EpaLineComment + "-- end 1") + { T20718.hs:8:5 })) + ,(L + (Anchor + { T20718.hs:11:1-8 } + (UnchangedAnchor)) + (EpaComment + (EpaLineComment + "-- end 2") + { T20718.hs:10:1-8 }))])) (VirtualBraces (1)) (Nothing) @@ -74,22 +89,7 @@ (AnnListItem []) (EpaComments - [(L - (Anchor - { T20718.hs:10:1-8 } - (UnchangedAnchor)) - (EpaComment - (EpaLineComment - "-- end 1") - { T20718.hs:8:5 })) - ,(L - (Anchor - { T20718.hs:11:1-8 } - (UnchangedAnchor)) - (EpaComment - (EpaLineComment - "-- end 2") - { T20718.hs:10:1-8 }))])) { T20718.hs:8:1-5 }) + [])) { T20718.hs:8:1-5 }) (ValD (NoExtField) (FunBind diff --git a/testsuite/tests/printer/Test20297.stdout b/testsuite/tests/printer/Test20297.stdout index df6f3347f9..180078c16a 100644 --- a/testsuite/tests/printer/Test20297.stdout +++ b/testsuite/tests/printer/Test20297.stdout @@ -50,14 +50,7 @@ (AnnListItem []) (EpaComments - [(L - (Anchor - { Test20297.hs:7:9-19 } - (UnchangedAnchor)) - (EpaComment - (EpaLineComment - "-- comment1") - { Test20297.hs:7:3-7 }))])) { Test20297.hs:(5,1)-(7,7) }) + [])) { Test20297.hs:(5,1)-(7,7) }) (ValD (NoExtField) (FunBind @@ -150,7 +143,14 @@ (AnnListItem []) (EpaComments - [])) { Test20297.hs:(9,1)-(11,26) }) + [(L + (Anchor + { Test20297.hs:7:9-19 } + (UnchangedAnchor)) + (EpaComment + (EpaLineComment + "-- comment1") + { Test20297.hs:7:3-7 }))])) { Test20297.hs:(9,1)-(11,26) }) (ValD (NoExtField) (FunBind |