fixes #9441
This commit is contained in:
parent
467274a19a
commit
7a0191ac7e
2 changed files with 62 additions and 2 deletions
|
|
@ -718,19 +718,37 @@ proc liftCapturedVars(n: PNode; owner: PSym; d: DetectionPass;
|
|||
# ------------------ old stuff -------------------------------------------
|
||||
|
||||
proc semCaptureSym*(s, owner: PSym) =
|
||||
discard """
|
||||
proc outer() =
|
||||
var x: int
|
||||
proc inner() =
|
||||
proc innerInner() =
|
||||
echo x
|
||||
innerInner()
|
||||
inner()
|
||||
# inner() takes a closure too!
|
||||
"""
|
||||
proc propagateClosure(start, last: PSym) =
|
||||
var o = start
|
||||
while o != nil and o.kind != skModule:
|
||||
if o == last: break
|
||||
o.typ.callConv = ccClosure
|
||||
o = o.skipGenericOwner
|
||||
|
||||
if interestingVar(s) and s.kind != skResult:
|
||||
if owner.typ != nil and not isGenericRoutine(owner):
|
||||
# XXX: is this really safe?
|
||||
# if we capture a var from another generic routine,
|
||||
# it won't be consider captured.
|
||||
var o = owner.skipGenericOwner
|
||||
while o.kind != skModule and o != nil:
|
||||
while o != nil and o.kind != skModule:
|
||||
if s.owner == o:
|
||||
if owner.typ.callConv in {ccClosure, ccDefault} or owner.kind == skIterator:
|
||||
owner.typ.callConv = ccClosure
|
||||
propagateClosure(owner.skipGenericOwner, s.owner)
|
||||
else:
|
||||
discard "do not produce an error here, but later"
|
||||
#echo "computing .closure for ", owner.name.s, " ", owner.info, " because of ", s.name.s
|
||||
#echo "computing .closure for ", owner.name.s, " because of ", s.name.s
|
||||
o = o.skipGenericOwner
|
||||
# since the analysis is not entirely correct, we don't set 'tfCapturesEnv'
|
||||
# here
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue