allow omitting stmts using finally as post expr blocks; make it consistent with else, except etc. (#21361)

allow omitting stmts using `finally` as post expr blocks
This commit is contained in:
ringabout 2023-02-14 14:29:30 +08:00 • committed by GitHub
commit 406d302131
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 1 deletions

View file

@ -1496,7 +1496,7 @@ proc postExprBlocks(p: var Parser, x: PNode): PNode =
result = makeCall(result) result = makeCall(result)
getTok(p) getTok(p)
skipComment(p, result) skipComment(p, result)
if p.tok.tokType notin {tkOf, tkElif, tkElse, tkExcept}: if p.tok.tokType notin {tkOf, tkElif, tkElse, tkExcept, tkFinally}:
var stmtList = newNodeP(nkStmtList, p) var stmtList = newNodeP(nkStmtList, p)
stmtList.add parseStmt(p) stmtList.add parseStmt(p)
# to keep backwards compatibility (see tests/vm/tstringnil) # to keep backwards compatibility (see tests/vm/tstringnil)

View file

@ -498,6 +498,13 @@ StmtList
StmtList StmtList
DiscardStmt DiscardStmt
Empty Empty
Call
Ident "foo"
Finally
StmtList
DiscardStmt
Empty
''' '''
""" """
@ -655,3 +662,7 @@ dumpTree:
discard discard
finally: finally:
discard discard
foo:
finally:
discard