From ba7c874a7df6e96dee2d7647a3f554d7476d3ae6 Mon Sep 17 00:00:00 2001 From: LemonBoy Date: Sun, 12 Aug 2018 20:41:48 +0200 Subject: [PATCH] Mysterious fix for #8550 (#8561) Replacing the `for` body with a nkEmpty node is not the right thing to do. --- compiler/transf.nim | 7 ++----- tests/closure/t8550.nim | 12 ++++++++++++ 2 files changed, 14 insertions(+), 5 deletions(-) create mode 100644 tests/closure/t8550.nim diff --git a/compiler/transf.nim b/compiler/transf.nim index dae8d1ee6d..c3bc29891a 100644 --- a/compiler/transf.nim +++ b/compiler/transf.nim @@ -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 diff --git a/tests/closure/t8550.nim b/tests/closure/t8550.nim new file mode 100644 index 0000000000..153246f085 --- /dev/null +++ b/tests/closure/t8550.nim @@ -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())