diff options
author | Araq <rumpf_a@web.de> | 2018-12-05 23:42:40 +0100 |
---|---|---|
committer | Araq <rumpf_a@web.de> | 2018-12-06 08:06:54 +0100 |
commit | 7a0191ac7ea2c3adfa303cfd6b1d1759a361e5c7 (patch) | |
tree | 49768e92e17a353ee67a9762d3e8b1fc334d2db6 /compiler/lambdalifting.nim | |
parent | 467274a19aa77a4f2db5bed32425e2dc0ee71212 (diff) | |
download | Nim-7a0191ac7ea2c3adfa303cfd6b1d1759a361e5c7.tar.gz |
fixes #9441
Diffstat (limited to 'compiler/lambdalifting.nim')
-rw-r--r-- | compiler/lambdalifting.nim | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/compiler/lambdalifting.nim b/compiler/lambdalifting.nim index e72cd5bd1..874cb4bd0 100644 --- a/compiler/lambdalifting.nim +++ b/compiler/lambdalifting.nim @@ -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 |