Fix double defer with break in closureiterators [backport] (#20630)
Fix double defer with break in closureiterators Signed-off-by: Tanguy <tanguy@status.im> Signed-off-by: Tanguy <tanguy@status.im>
This commit is contained in:
parent
69cb671d8d
commit
008c3ec76a
2 changed files with 32 additions and 0 deletions
|
|
@ -1372,6 +1372,7 @@ proc preprocess(c: var PreprocessContext; n: PNode): PNode =
|
||||||
# detect: 'finally: raises X' which is currently not supported. We produce
|
# detect: 'finally: raises X' which is currently not supported. We produce
|
||||||
# an error for this case for now. All this will be done properly with Yuriy's
|
# an error for this case for now. All this will be done properly with Yuriy's
|
||||||
# patch.
|
# patch.
|
||||||
|
|
||||||
result = n
|
result = n
|
||||||
case n.kind
|
case n.kind
|
||||||
of nkTryStmt:
|
of nkTryStmt:
|
||||||
|
|
@ -1388,6 +1389,7 @@ proc preprocess(c: var PreprocessContext; n: PNode): PNode =
|
||||||
discard c.finallys.pop()
|
discard c.finallys.pop()
|
||||||
|
|
||||||
of nkWhileStmt, nkBlockStmt:
|
of nkWhileStmt, nkBlockStmt:
|
||||||
|
if n.hasYields == false: return n
|
||||||
c.blocks.add((n, c.finallys.len))
|
c.blocks.add((n, c.finallys.len))
|
||||||
for i in 0 ..< n.len:
|
for i in 0 ..< n.len:
|
||||||
result[i] = preprocess(c, n[i])
|
result[i] = preprocess(c, n[i])
|
||||||
|
|
|
||||||
|
|
@ -38,6 +38,10 @@ nested finally
|
||||||
outer finally
|
outer finally
|
||||||
nested finally
|
nested finally
|
||||||
outer finally
|
outer finally
|
||||||
|
In defer
|
||||||
|
trying
|
||||||
|
exception caught
|
||||||
|
finally block
|
||||||
'''
|
'''
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
@ -362,3 +366,29 @@ block:
|
||||||
|
|
||||||
for _ in p4():
|
for _ in p4():
|
||||||
discard
|
discard
|
||||||
|
|
||||||
|
# bug #18824
|
||||||
|
iterator poc_iterator: int {.closure.} =
|
||||||
|
block:
|
||||||
|
try:
|
||||||
|
break
|
||||||
|
finally:
|
||||||
|
echo "In defer"
|
||||||
|
|
||||||
|
for _ in poc_iterator():
|
||||||
|
discard
|
||||||
|
|
||||||
|
# bug #20624
|
||||||
|
iterator tryFinally() {.closure.} =
|
||||||
|
block route:
|
||||||
|
try:
|
||||||
|
echo "trying"
|
||||||
|
raise
|
||||||
|
except:
|
||||||
|
echo "exception caught"
|
||||||
|
break route
|
||||||
|
finally:
|
||||||
|
echo "finally block"
|
||||||
|
|
||||||
|
var x = tryFinally
|
||||||
|
x()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue