mirror of
https://github.com/nim-lang/Nim.git
synced 2026-06-04 02:44:44 +00:00
Replacing the `for` body with a nkEmpty node is not the right thing to do.
This commit is contained in:
@@ -539,11 +539,8 @@ proc transformFor(c: PTransf, n: PNode): PTransNode =
|
||||
if call.kind notin nkCallKinds or call.sons[0].kind != nkSym or
|
||||
call.sons[0].typ.callConv == ccClosure:
|
||||
n.sons[length-1] = transformLoopBody(c, n.sons[length-1]).PNode
|
||||
if not c.tooEarly:
|
||||
n.sons[length-2] = transform(c, n.sons[length-2]).PNode
|
||||
result[1] = lambdalifting.liftForLoop(c.graph, n, getCurrOwner(c)).PTransNode
|
||||
else:
|
||||
result[1] = newNode(nkEmpty).PTransNode
|
||||
n.sons[length-2] = transform(c, n.sons[length-2]).PNode
|
||||
result[1] = lambdalifting.liftForLoop(c.graph, n, getCurrOwner(c)).PTransNode
|
||||
discard c.breakSyms.pop
|
||||
return result
|
||||
|
||||
|
||||
12
tests/closure/t8550.nim
Normal file
12
tests/closure/t8550.nim
Normal file
@@ -0,0 +1,12 @@
|
||||
discard """
|
||||
output: "@[\"42\"]"
|
||||
"""
|
||||
|
||||
proc chk_fail(): seq[string] =
|
||||
iterator x(): int {.closure.} = yield 42
|
||||
proc f(cl: iterator(): int {.closure.}): seq[string] =
|
||||
result = @[]
|
||||
for i in cl(): result.add($i)
|
||||
result = f(x)
|
||||
|
||||
echo(chk_fail())
|
||||
Reference in New Issue
Block a user