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

(cherry picked from commit 0d734d7966)
This commit is contained in:
Yuriy Glukhov
2022-08-03 08:46:36 +02:00
committed by narimiran
parent c484943cab
commit 65e0906e69
2 changed files with 15 additions and 4 deletions

View File

@@ -822,10 +822,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