fixes #21138; closure func used in the loop (#25196)

fixes #21138
This commit is contained in:
ringabout
2025-09-27 11:54:22 +08:00
committed by GitHub
parent f4497c6158
commit cc49bf07fe
2 changed files with 16 additions and 1 deletions

View File

@@ -329,7 +329,7 @@ proc introduceNewLocalVars(c: PTransf, n: PNode): PNode =
if a.kind == nkSym:
n[1] = transformSymAux(c, a)
return n
of nkProcDef: # todo optimize nosideeffects?
of nkProcDef, nkFuncDef, nkMethodDef, nkConverterDef: # todo optimize nosideeffects?
result = newTransNode(n)
let x = newSymNode(copySym(n[namePos].sym, c.idgen))
c.transCon.mapping[n[namePos].sym.itemId] = x

View File

@@ -145,3 +145,18 @@ proc main123() =
discard
main123()
# bug #21138
iterator ubi(): int =
when nimvm:
yield 0
else:
yield 0
block:
for k in ubi():
func e() {.closure.} = discard
static:
for k in ubi():
func e() {.closure.} = discard