Skip to content

Commit

Permalink
fixes #21144; try expression will not match the less indentation exce…
Browse files Browse the repository at this point in the history
…pt (#21152)

fixes #21144; try expression will not match the less indent except
  • Loading branch information
ringabout authored Dec 21, 2022
1 parent 81d8ea9 commit d0721ea
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
4 changes: 3 additions & 1 deletion compiler/parser.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1770,11 +1770,13 @@ proc parseTry(p: var Parser; isExpr: bool): PNode =
#| (optInd 'except' optionalExprList colcom stmt)*
#| (optInd 'finally' colcom stmt)?
result = newNodeP(nkTryStmt, p)
let parentIndent = p.currInd # isExpr
getTok(p)
colcom(p, result)
result.add(parseStmt(p))
var b: PNode = nil
while sameOrNoInd(p) or isExpr:

while sameOrNoInd(p) or (isExpr and parentIndent <= p.tok.indent):
case p.tok.tokType
of tkExcept:
b = newNodeP(nkExceptBranch, p)
Expand Down
27 changes: 27 additions & 0 deletions tests/parser/ttry.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# bug #21144
block:
try:
let c = try:
10
except ValueError as exc:
10
except ValueError as exc:
discard

if true:
block:
let c = try:
10
except ValueError as exc:
10
except OSError:
99


try:
let c = try:
10
except ValueError as exc:
10
except ValueError as exc:
discard

0 comments on commit d0721ea

Please sign in to comment.