mirror of
https://github.com/nim-lang/Nim.git
synced 2026-04-25 16:53:59 +00:00
bugfix: detect captures in non-closure inner procs
This commit is contained in:
@@ -764,7 +764,10 @@ proc semCaptureSym*(s, owner: PSym) =
|
||||
var o = owner.skipGenericOwner
|
||||
while o.kind != skModule and o != nil:
|
||||
if s.owner == o:
|
||||
owner.typ.callConv = ccClosure
|
||||
if owner.typ.callConv in {ccClosure, ccDefault} or owner.kind == skIterator:
|
||||
owner.typ.callConv = ccClosure
|
||||
else:
|
||||
discard "do not produce an error here, but later"
|
||||
#echo "computing .closure for ", owner.name.s, " ", owner.info, " because of ", s.name.s
|
||||
o = o.skipGenericOwner
|
||||
# since the analysis is not entirely correct, we don't set 'tfCapturesEnv'
|
||||
|
||||
12
tests/closure/tinvalidclosure3.nim
Normal file
12
tests/closure/tinvalidclosure3.nim
Normal file
@@ -0,0 +1,12 @@
|
||||
discard """
|
||||
line: 9
|
||||
errormsg: "illegal capture 'x'"
|
||||
"""
|
||||
|
||||
proc outer(arg: string) =
|
||||
var x = 0
|
||||
proc inner {.inline.} =
|
||||
echo "inner", x
|
||||
inner()
|
||||
|
||||
outer("abc")
|
||||
Reference in New Issue
Block a user