From aa8715afdede871d673a3074e95a4155185eb2e8 Mon Sep 17 00:00:00 2001 From: metagn Date: Thu, 17 Apr 2025 00:44:31 +0300 Subject: [PATCH] fix stmtlist expression indent regression (#24883) follows up #24855 Before #24855, the test would work because the indentation of the `;` token would be passed to `semiStmtList` and so its indentation of `-1` would be used. Now the `;` token is skipped and the indentation of the first `discard` is used which is > -1. However the second discard has an indentation of -1 because it's on the same line: this fails the `sameInd(p) or realInd(p)` check since -1 is never >= the indent of the first discard. For compatibility with the parser up to this point this indent check is entirely removed, meaning the indent is ignored. Because the `;` is basically never on a separate line, this was already the case for basically every use. `semiStmtList` is wrapped in a `withInd` anyway which resets the indent after it's done, since the entire statement list is wrapped in a `()`. To disallow dedents, the above check could be fixed to use `sameOrNoInd` instead of `sameInd`, which is done in the commented version of this check. (cherry picked from commit 3d14381473fd478432cb8fab04d0501b26db775b) --- compiler/parser.nim | 5 +++-- tests/parser/tstmtlistexprindent.nim | 7 +++++++ 2 files changed, 10 insertions(+), 2 deletions(-) create mode 100644 tests/parser/tstmtlistexprindent.nim diff --git a/compiler/parser.nim b/compiler/parser.nim index 7f438f4208..03c3ac2648 100644 --- a/compiler/parser.nim +++ b/compiler/parser.nim @@ -638,8 +638,9 @@ proc semiStmtList(p: var Parser, result: PNode) = getTok(p) if p.tok.tokType == tkParRi: break - elif not (sameInd(p) or realInd(p)): - parMessage(p, errInvalidIndentation) + # ignore indent: + #elif not (sameOrNoInd(p) or realInd(p)): + # parMessage(p, errInvalidIndentation) let a = complexOrSimpleStmt(p) if a.kind == nkEmpty: parMessage(p, errExprExpected, p.tok) diff --git a/tests/parser/tstmtlistexprindent.nim b/tests/parser/tstmtlistexprindent.nim new file mode 100644 index 0000000000..5c6c25151c --- /dev/null +++ b/tests/parser/tstmtlistexprindent.nim @@ -0,0 +1,7 @@ +type E = enum A, B, C +proc junk(e: E) = + case e + of A: (echo "a"; + discard; discard; + discard) + else: discard