Skip to content

Commit 3d14381

Browse files
authored
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.
1 parent 9f359e8 commit 3d14381

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

compiler/parser.nim

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -638,8 +638,9 @@ proc semiStmtList(p: var Parser, result: PNode) =
638638
getTok(p)
639639
if p.tok.tokType == tkParRi:
640640
break
641-
elif not (sameInd(p) or realInd(p)):
642-
parMessage(p, errInvalidIndentation)
641+
# ignore indent:
642+
#elif not (sameOrNoInd(p) or realInd(p)):
643+
# parMessage(p, errInvalidIndentation)
643644
let a = complexOrSimpleStmt(p)
644645
if a.kind == nkEmpty:
645646
parMessage(p, errExprExpected, p.tok)

tests/parser/tstmtlistexprindent.nim

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
type E = enum A, B, C
2+
proc junk(e: E) =
3+
case e
4+
of A: (echo "a";
5+
discard; discard;
6+
discard)
7+
else: discard

0 commit comments

Comments
 (0)