mirror of
https://github.com/nim-lang/Nim.git
synced 2025-12-28 17:04:41 +00:00
This commit is contained in:
@@ -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
|
||||
|
||||
20
tests/closure/t20152.nim
Normal file
20
tests/closure/t20152.nim
Normal file
@@ -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()
|
||||
Reference in New Issue
Block a user