diff options
author | ringabout <43030857+ringabout@users.noreply.github.com> | 2023-07-22 12:37:27 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-07-22 06:37:27 +0200 |
commit | b02c1dd6ca96548b47d978f96278c67bf59e9d9e (patch) | |
tree | 6c4d0c54248ec928adce49f530029f6af4a24f9b | |
parent | 993fcf5bdac32964237b29e279ecf839095ac609 (diff) | |
download | Nim-b02c1dd6ca96548b47d978f96278c67bf59e9d9e.tar.gz |
fixes #22297; return in the finally in the closure iterators (#22300)
ref #22297; return in the finally in the closure iterators
-rw-r--r-- | compiler/closureiters.nim | 4 | ||||
-rw-r--r-- | tests/closure/tclosure.nim | 11 |
2 files changed, 14 insertions, 1 deletions
diff --git a/compiler/closureiters.nim b/compiler/closureiters.nim index ae4fde0f6..87c5b795e 100644 --- a/compiler/closureiters.nim +++ b/compiler/closureiters.nim @@ -855,7 +855,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) diff --git a/tests/closure/tclosure.nim b/tests/closure/tclosure.nim index fa1f79ffe..401a71d40 100644 --- a/tests/closure/tclosure.nim +++ b/tests/closure/tclosure.nim @@ -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 |