Skip to content

Commit cc49bf0

Browse files
authored
fixes #21138; closure func used in the loop (#25196)
fixes #21138
1 parent f4497c6 commit cc49bf0

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

compiler/transf.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ proc introduceNewLocalVars(c: PTransf, n: PNode): PNode =
329329
if a.kind == nkSym:
330330
n[1] = transformSymAux(c, a)
331331
return n
332-
of nkProcDef: # todo optimize nosideeffects?
332+
of nkProcDef, nkFuncDef, nkMethodDef, nkConverterDef: # todo optimize nosideeffects?
333333
result = newTransNode(n)
334334
let x = newSymNode(copySym(n[namePos].sym, c.idgen))
335335
c.transCon.mapping[n[namePos].sym.itemId] = x

tests/iter/titer.nim

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,3 +145,18 @@ proc main123() =
145145
discard
146146

147147
main123()
148+
149+
# bug #21138
150+
iterator ubi(): int =
151+
when nimvm:
152+
yield 0
153+
else:
154+
yield 0
155+
156+
block:
157+
for k in ubi():
158+
func e() {.closure.} = discard
159+
160+
static:
161+
for k in ubi():
162+
func e() {.closure.} = discard

0 commit comments

Comments
 (0)