fixes #22297; return in the finally in the closure iterators (#22300)

ref #22297; return in the finally in the closure iterators

(cherry picked from commit b02c1dd6ca)
This commit is contained in:
ringabout
2023-07-22 12:37:27 +08:00
committed by narimiran
parent 0ac3461c7d
commit ba2d8ba468
2 changed files with 14 additions and 1 deletions

View File

@@ -852,7 +852,9 @@ proc transformReturnsInTry(ctx: var Ctx, n: PNode): PNode =
case n.kind
of nkReturnStmt:
# We're somewhere in try, transform to finally unrolling
assert(ctx.nearestFinally != 0)
if ctx.nearestFinally == 0:
# return is within the finally
return
result = newNodeI(nkStmtList, n.info)

View File

@@ -491,3 +491,14 @@ block tnoclosure:
row = zip(row & @[0], @[0] & row).mapIt(it[0] + it[1])
echo row
pascal(10)
block: # bug #22297
iterator f: int {.closure.} =
try:
yield 12
finally:
return 14
let s = f
doAssert s() == 12
doAssert s() == 14