Fixed compilation of void closureiters with try stmt (#20138) [backport]

This commit is contained in:
Yuriy Glukhov 2022-08-03 08:46:36 +02:00 • committed by GitHub
commit 0d734d7966
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 4 deletions

View file

@ -825,10 +825,13 @@ proc newEndFinallyNode(ctx: var Ctx, info: TLineInfo): PNode =
let retStmt =
if ctx.nearestFinally == 0:
# last finally, we can return
let asgn = newTree(nkFastAsgn,
newSymNode(getClosureIterResult(ctx.g, ctx.fn, ctx.idgen), info),
ctx.newTmpResultAccess())
newTree(nkReturnStmt, asgn)
let retValue = if ctx.fn.typ[0].isNil:
ctx.g.emptyNode
else:
newTree(nkFastAsgn,
newSymNode(getClosureIterResult(ctx.g, ctx.fn, ctx.idgen), info),
ctx.newTmpResultAccess())
newTree(nkReturnStmt, retValue)
else:
# bubble up to next finally
newTree(nkGotoState, ctx.g.newIntLit(info, ctx.nearestFinally))

View file

@ -495,3 +495,11 @@ block: #17849 - yield in case subject
yield 5
test(it, 1, 2, 13, 5)
block: # void iterator
iterator it() {.closure.} =
try:
yield
except:
discard
var a = it