fixes #25591; error with capture in closure iterator

This commit is contained in:
ringabout
2026-05-28 22:27:49 +08:00
parent 8771451701
commit 4c5ae4d1fc
2 changed files with 13 additions and 0 deletions

View File

@@ -520,6 +520,8 @@ proc detectCapturedVars(n: PNode; owner: PSym; c: var DetectionPass) =
of nkLambdaKinds, nkIteratorDef:
if n.typ != nil:
detectCapturedVars(n[namePos], owner, c)
of nkClosure:
detectCapturedVars(n[1], owner, c)
of nkReturnStmt:
detectCapturedVars(n[0], owner, c)
of nkIdentDefs:

View File

@@ -239,6 +239,17 @@ block t2023_objiter:
var o = init()
echo(o.iter())
block: # bug #25591
iterator h(): int =
let n = 0
(proc() = discard n)()
yield 0
proc a() =
iterator m(): int {.closure.} = (for _ in h(): discard)
let _ = m
a()
block:
# bug #13739