@@ -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
@@ -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
0 commit comments