From 66cbcaab8474f5ff3480e7a9bc55df249548a90c Mon Sep 17 00:00:00 2001 From: Bung Date: Fri, 21 Oct 2022 15:59:05 +0800 Subject: fix #20152 Illegal capture of closure iterator, when should be legal (#20607) --- compiler/lambdalifting.nim | 2 +- tests/closure/t20152.nim | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 tests/closure/t20152.nim diff --git a/compiler/lambdalifting.nim b/compiler/lambdalifting.nim index a34f4ba94..9790eefd8 100644 --- a/compiler/lambdalifting.nim +++ b/compiler/lambdalifting.nim @@ -458,7 +458,7 @@ proc detectCapturedVars(n: PNode; owner: PSym; c: var DetectionPass) = else: discard addField(obj, s, c.graph.cache, c.idgen) # direct or indirect dependency: - elif (innerProc and s.typ.callConv == ccClosure) or interestingVar(s): + elif (innerProc and not s.isIterator and s.typ.callConv == ccClosure) or interestingVar(s): discard """ proc outer() = var x: int diff --git a/tests/closure/t20152.nim b/tests/closure/t20152.nim new file mode 100644 index 000000000..484ea0741 --- /dev/null +++ b/tests/closure/t20152.nim @@ -0,0 +1,20 @@ +discard """ + action: compile +""" + +proc foo() = + iterator it():int {.closure.} = + yield 1 + proc useIter() {.nimcall.} = + var iii = it # <-- illegal capture + doAssert iii() == 1 + useIter() +foo() + +proc foo2() = + proc bar() = # Local function, but not a closure, because no captures + echo "hi" + proc baz() {.nimcall.} = # Calls local function + bar() + baz() +foo2() -- cgit 1.4.1-2-gfad0 8f07aee36f68bcd270889d20c2d22b9aa0b'>blame commit diff stats
path: root/arc/scratch.vim
blob: 83b055393824b3fc239406fc18720aabb784da33 (plain) (tree)
1
2
3
4
5
6
7
8
9
10