From 299351a909ee4827984eb9390f8ed55437bd60a9 Mon Sep 17 00:00:00 2001 From: Andreas Rumpf Date: Wed, 11 May 2016 18:16:25 +0200 Subject: [PATCH] fixes #4070 --- compiler/lambdalifting.nim | 1 + tests/closure/tdeeplynested.nim | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 tests/closure/tdeeplynested.nim diff --git a/compiler/lambdalifting.nim b/compiler/lambdalifting.nim index 959632bab..753602c80 100644 --- a/compiler/lambdalifting.nim +++ b/compiler/lambdalifting.nim @@ -716,6 +716,7 @@ proc liftCapturedVars(n: PNode; owner: PSym; d: DetectionPass; #localError(n.info, "internal error: closure to closure created") # now we know better, so patch it: n.sons[0] = x.sons[0] + n.sons[1] = x.sons[1] of nkLambdaKinds, nkIteratorDef: if n.typ != nil and n[namePos].kind == nkSym: let m = newSymNode(n[namePos].sym) diff --git a/tests/closure/tdeeplynested.nim b/tests/closure/tdeeplynested.nim new file mode 100644 index 000000000..0cd9a3694 --- /dev/null +++ b/tests/closure/tdeeplynested.nim @@ -0,0 +1,20 @@ +discard """ + output: '''108''' +""" + +# bug #4070 + +proc id(f: (proc())): auto = + return f + +proc foo(myinteger: int): (iterator(): int) = + return iterator(): int {.closure.} = + proc bar() = + proc kk() = + echo "int: ", myinteger + + kk() + + id(bar)() + +discard foo(108)()