@@ -59,9 +59,6 @@ object CheckCaptures:
5959
6060 def isOutermost = outer0 == null
6161
62- /** If an environment is open it tracks free references */
63- def isOpen (using Context ) = ! captured.isAlwaysEmpty && kind != EnvKind .Boxed
64-
6562 def outersIterator : Iterator [Env ] = new :
6663 private var cur = Env .this
6764 def hasNext = ! cur.isOutermost
@@ -466,7 +463,7 @@ class CheckCaptures extends Recheck, SymTransformer:
466463 def checkUseDeclared (c : Capability , env : Env , lastEnv : Env | Null ) =
467464 if lastEnv != null && env.nestedClosure.exists && env.nestedClosure == lastEnv.owner then
468465 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
470467 case ref : NamedType if ! ref.symbol.isUseParam =>
471468 val what = if ref.isType then " Capture set parameter" else " Local reach capability"
472469 report.error(
@@ -528,7 +525,7 @@ class CheckCaptures extends Recheck, SymTransformer:
528525 case _ =>
529526
530527 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
532529 // Only captured references that are visible from the environment
533530 // should be included.
534531 val included = cs.filter: c =>
@@ -556,7 +553,7 @@ class CheckCaptures extends Recheck, SymTransformer:
556553 def isRetained (ref : Capability ): Boolean = ref.pathRoot match
557554 case root : ThisType => ctx.owner.isContainedIn(root.cls)
558555 case _ => true
559- if sym.exists && curEnv.isOpen then
556+ if sym.exists && curEnv.kind != EnvKind . Boxed then
560557 markFree(capturedVars(sym).filter(isRetained), tree)
561558
562559 /** If `tp` (possibly after widening singletons) is an ExprType
@@ -1106,7 +1103,6 @@ class CheckCaptures extends Recheck, SymTransformer:
11061103 try
11071104 // Setup environment to reflect the new owner.
11081105 val envForOwner : Map [Symbol , Env ] = curEnv.outersIterator
1109- .takeWhile(e => ! capturedVars(e.owner).isAlwaysEmpty) // no refs can leak beyond this point
11101106 .map(e => (e.owner, e))
11111107 .toMap
11121108 def restoreEnvFor (sym : Symbol ): Env =
@@ -1142,8 +1138,7 @@ class CheckCaptures extends Recheck, SymTransformer:
11421138 checkSubset(capturedVars(parent.tpe.classSymbol), localSet, parent.srcPos,
11431139 i " \n of the references allowed to be captured by $cls" )
11441140 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)
11471142 try
11481143 val thisSet = cls.classInfo.selfType.captureSet.withDescription(i " of the self type of $cls" )
11491144 checkSubset(localSet, thisSet, tree.srcPos) // (2)
0 commit comments