Repository navigation
Conversation
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
fixes #26694
After a comment token,
emitToksetsem.lastToktotkComment. For the next line,emitTokchecks whetherlastTokis a comma, an open bracket or an operator to decide if the line continues an expression. Because the comment hides the comma (orand/or) before it, the next line is treated as a new statement: its column is pushed onindentStackand the line is written atindentStack.high * indWidth. The pushed column is popped again only at the next dedent, so the statement after the expression (thereturnin the issue) is written one level too shallow, andfinalCheckfails withinvalid indentation.Fix: a comment no longer updates
lastTok, so the token after it is laid out in the same context as the token before it.Test:
nimpretty/tests/tcommentinlist.nim, with the example from the issue and the same pattern afterandin anifcondition.Verification, on macOS arm64:
nim r nimpretty/tester.nimfails ontcommentinlist(invalid indentation); after the fix all files are identical, including the pretty(pretty(x)) runs. The expected output compiles and prints the same as the input.compiler/*.nim,lib/pure/*.nimandlib/std/*.nim(307 files). 23 files failed before, 18 fail after; the 18 fail with the same error at the same position with both versions. The 5 files that now format (compiler/ccgexprs.nim,linter.nim,sem.nim,semexprs.nim,seminst.nim) failed because of this bug: a comment afterand/orin anifcondition. 6 more files differ, all in lines that follow a comment inside an expression: those lines now keep their original alignment instead of moving left (docgen.nim,extccomp.nim,renderer.nim,semtypinst.nim,parseutils.nim,semmagic.nim). Inparseutils.nimthe trailing comment# ldexp?is now one space after the code because the line keeps its column; insemmagic.nimthe line keeps its column, is then longer than 80 characters and is split.emitTok, notoptionalIsGood, so it does not overlap with fixes #26691; fixes #26692; nimpretty keeps the space after a binary operator when it joins lines #26878 or fixes #26693; nimpretty no longer writes an empty line when it splits a joined line #26880. The three branches merge without conflicts and the tester passes on the merged tree.The error message naming
nimpretty_bug.nim, mentioned at the end of the issue, is not changed here.