Fix nested finally handling in closureiters [backport] (#19933)

* Fix nested finally handling in closureiters

* Fix CI

* review comment

* third time the charm

* Update compiler/closureiters.nim

Co-authored-by: Dominik Picheta <dominikpicheta@googlemail.com>

Co-authored-by: Dominik Picheta <dominikpicheta@googlemail.com>
(cherry picked from commit fb5fbf1e08)
This commit is contained in:
Tanguy
2022-07-11 11:28:52 +02:00
committed by narimiran
parent b1f325d641
commit 9508b06513
2 changed files with 101 additions and 6 deletions

View File

@@ -29,6 +29,14 @@ end
9018
@[1, 2]
@[1, 2, 3]
nested finally
outer finally
nested finally
outer finally
nested finally
outer finally
nested finally
outer finally
'''
"""
@@ -274,3 +282,71 @@ iterator cc() {.closure.} =
break
var a2 = cc
block:
# bug #19911 (return in nested try)
# try yield -> try
iterator p1: int {.closure.} =
try:
yield 0
try:
return
finally:
echo "nested finally"
echo "shouldn't run"
finally:
echo "outer finally"
echo "shouldn't run"
for _ in p1():
discard
# try -> try yield
iterator p2: int {.closure.} =
try:
try:
yield 0
return
finally:
echo "nested finally"
echo "shouldn't run"
finally:
echo "outer finally"
echo "shouldn't run"
for _ in p2():
discard
# try yield -> try yield
iterator p3: int {.closure.} =
try:
yield 0
try:
yield 0
return
finally:
echo "nested finally"
echo "shouldn't run"
finally:
echo "outer finally"
echo "shouldn't run"
for _ in p3():
discard
# try -> try
iterator p4: int {.closure.} =
try:
try:
return
finally:
echo "nested finally"
echo "shouldn't run"
finally:
echo "outer finally"
echo "shouldn't run"
for _ in p4():
discard