@@ -59,9 +59,6 @@ object CheckCaptures:
59
59
60
60
def isOutermost = outer0 == null
61
61
62
- /** If an environment is open it tracks free references */
63
- def isOpen (using Context ) = ! captured.isAlwaysEmpty && kind != EnvKind .Boxed
64
-
65
62
def outersIterator : Iterator [Env ] = new :
66
63
private var cur = Env .this
67
64
def hasNext = ! cur.isOutermost
@@ -466,7 +463,7 @@ class CheckCaptures extends Recheck, SymTransformer:
466
463
def checkUseDeclared (c : Capability , env : Env , lastEnv : Env | Null ) =
467
464
if lastEnv != null && env.nestedClosure.exists && env.nestedClosure == lastEnv.owner then
468
465
assert(ccConfig.deferredReaches) // access is from a nested closure under deferredReaches, so it's OK
469
- else c.pathRoot match
466
+ else c.paramPathRoot match
470
467
case ref : NamedType if ! ref.symbol.isUseParam =>
471
468
val what = if ref.isType then " Capture set parameter" else " Local reach capability"
472
469
report.error(
@@ -528,7 +525,7 @@ class CheckCaptures extends Recheck, SymTransformer:
528
525
case _ =>
529
526
530
527
def recur (cs : CaptureSet , env : Env , lastEnv : Env | Null ): Unit =
531
- if env.isOpen && ! env.owner.isStaticOwner && ! cs.isAlwaysEmpty then
528
+ if env.kind != EnvKind . Boxed && ! env.owner.isStaticOwner && ! cs.isAlwaysEmpty then
532
529
// Only captured references that are visible from the environment
533
530
// should be included.
534
531
val included = cs.filter: c =>
@@ -556,7 +553,7 @@ class CheckCaptures extends Recheck, SymTransformer:
556
553
def isRetained (ref : Capability ): Boolean = ref.pathRoot match
557
554
case root : ThisType => ctx.owner.isContainedIn(root.cls)
558
555
case _ => true
559
- if sym.exists && curEnv.isOpen then
556
+ if sym.exists && curEnv.kind != EnvKind . Boxed then
560
557
markFree(capturedVars(sym).filter(isRetained), tree)
561
558
562
559
/** If `tp` (possibly after widening singletons) is an ExprType
@@ -1106,7 +1103,6 @@ class CheckCaptures extends Recheck, SymTransformer:
1106
1103
try
1107
1104
// Setup environment to reflect the new owner.
1108
1105
val envForOwner : Map [Symbol , Env ] = curEnv.outersIterator
1109
- .takeWhile(e => ! capturedVars(e.owner).isAlwaysEmpty) // no refs can leak beyond this point
1110
1106
.map(e => (e.owner, e))
1111
1107
.toMap
1112
1108
def restoreEnvFor (sym : Symbol ): Env =
@@ -1142,8 +1138,7 @@ class CheckCaptures extends Recheck, SymTransformer:
1142
1138
checkSubset(capturedVars(parent.tpe.classSymbol), localSet, parent.srcPos,
1143
1139
i " \n of the references allowed to be captured by $cls" )
1144
1140
val saved = curEnv
1145
- if localSet ne CaptureSet .empty then
1146
- curEnv = Env (cls, EnvKind .Regular , localSet, curEnv)
1141
+ curEnv = Env (cls, EnvKind .Regular , localSet, curEnv)
1147
1142
try
1148
1143
val thisSet = cls.classInfo.selfType.captureSet.withDescription(i " of the self type of $cls" )
1149
1144
checkSubset(localSet, thisSet, tree.srcPos) // (2)
0 commit comments