fixes #21110; duplicate proc definitions for inline iters (#21136)

fixes #21110; duplicate proc definitions for iters

(cherry picked from commit 88114948c4)
This commit is contained in:
ringabout
2023-06-23 04:17:23 +08:00
committed by narimiran
parent 238efc025e
commit 3bd03d71a0
2 changed files with 23 additions and 0 deletions

View File

@@ -316,6 +316,14 @@ proc introduceNewLocalVars(c: PTransf, n: PNode): PNode =
if a.kind == nkSym:
n[1] = transformSymAux(c, a)
return n
of nkProcDef: # todo optimize nosideeffects?
result = newTransNode(n)
let x = freshVar(c, n[namePos].sym)
idNodeTablePut(c.transCon.mapping, n[namePos].sym, x)
result[namePos] = x # we have to copy proc definitions for iters
for i in 1..<n.len:
result[i] = introduceNewLocalVars(c, n[i])
result[namePos].sym.ast = result
else:
result = newTransNode(n)
for i in 0..<n.len:

View File

@@ -112,3 +112,18 @@ let res = collect:
fn2(v2)
doAssert res == @[42, 43, 43, 44]
block: # bug #21110
iterator p(): int =
when nimvm:
yield 0
else:
yield 0
template foo =
for k in p():
let m = ""
proc e() = discard m & ""
e()
static: foo()
foo()