Skip to content

Commit 8b24687

Browse files
committed
ok
1 parent 4bde4c2 commit 8b24687

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

compiler/closureiters.nim

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -916,19 +916,22 @@ proc transformBreakStmt(ctx: var Ctx, n: PNode): PNode =
916916
let targetName = if n[0].kind == nkSym: n[0].sym else: nil
917917
var finallyChain = newSeq[PNode]()
918918
919+
var targetFound = false
919920
for i in countdown(ctx.finallyPathStack.high, 0):
920921
let b = ctx.finallyPathStack[i].n
921922
# echo "STACK ", i, " ", b.kind
922923
if b.kind == nkBlockStmt and targetName != nil and b[0].sym == targetName:
923924
finallyChain.add(ctx.finallyPathStack[i].exitLabel)
925+
targetFound = true
924926
break
925927
elif b.kind == nkWhileStmt and targetName == nil:
926928
finallyChain.add(ctx.finallyPathStack[i].exitLabel)
929+
targetFound = true
927930
break
928931
elif b.kind == nkFinally:
929932
finallyChain.add(ctx.finallyPathStack[i].enterLabel)
930933

931-
if finallyChain.len > 0:
934+
if targetFound and finallyChain.len > 0:
932935
result = ctx.newJumpAlongFinallyChain(finallyChain, n.info)
933936
else:
934937
result = n

tests/iter/tyieldintry.nim

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -667,3 +667,24 @@ block: #21235
667667
except ValueError:
668668
ok = true
669669
doAssert(ok)
670+
671+
block: # break in for without yield in try
672+
iterator it(): int {.closure.} =
673+
try:
674+
block:
675+
checkpoint(1)
676+
for i in 0 .. 10:
677+
checkpoint(2)
678+
break
679+
checkpoint(3)
680+
681+
try:
682+
yield 4
683+
except:
684+
checkpoint(123)
685+
except:
686+
discard
687+
finally:
688+
checkpoint(5)
689+
690+
test(it, 1, 2, 3, 4, 5)

0 commit comments

Comments
 (0)