mirror of
https://github.com/nim-lang/Nim.git
synced 2026-01-03 11:42:33 +00:00
fixes #21110; duplicate proc definitions for iters
(cherry picked from commit 88114948c4)
This commit is contained in:
@@ -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:
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user