@@ -655,8 +655,15 @@ object CaptureSet:
655655 inline val debugVars = false
656656 inline val debugTarget = 1745
657657
658- /** The subclass of captureset variables with given initial elements */
659- class Var (initialOwner : Symbol = NoSymbol , initialElems : Refs = emptyRefs, underBox : Boolean = false )(using /* @constructorOnly*/ ictx : Context ) extends CaptureSet :
658+ /** The subclass of captureset variables with given initial elements
659+ * @param initialOwner the initial owner. This is the real owner, except that
660+ * it can be change in HiddenSets. Used for level checking
661+ * if different from NoSymbol.
662+ * @param initialElems the initial elements
663+ * @param nestedOK relevant only if owner != NoSymbol. If true the set accepts
664+ * elements that are directly owned by owner.
665+ */
666+ class Var (initialOwner : Symbol = NoSymbol , initialElems : Refs = emptyRefs, nestedOK : Boolean = true )(using /* @constructorOnly*/ ictx : Context ) extends CaptureSet :
660667
661668 override def owner = initialOwner
662669
@@ -682,7 +689,7 @@ object CaptureSet:
682689 protected var myElems : Refs = initialElems
683690
684691 if debugVars && id == debugTarget then
685- println(i " ###INIT ELEMS of $id to $initialElems" )
692+ println(i " ###INIT ELEMS of $id of class $getClass in $initialOwner , $nestedOK to $initialElems" )
686693 assert(false )
687694
688695 def elems : Refs = myElems
@@ -828,15 +835,16 @@ object CaptureSet:
828835
829836 def levelOK (elem : Capability )(using Context ): Boolean = elem match
830837 case elem @ ResultCap (binder) =>
831- rootLimit == null && ( this . isInstanceOf [ BiMapped ] || isPartOf(binder.resType) )
838+ rootLimit == null && isPartOf(binder.resType)
832839 case GlobalCap =>
833840 rootLimit == null
834841 case elem : ParamRef =>
835- this . isInstanceOf [ BiMapped ] || isPartOf(elem.binder.resType)
842+ isPartOf(elem.binder.resType)
836843 case _ =>
837844 if owner.exists then
838845 val elemVis = elem.visibility
839846 ! elemVis.isProperlyContainedIn(owner)
847+ || nestedOK && elemVis.owner == owner
840848 else true
841849
842850 def addDependent (cs : CaptureSet )(using Context , VarState ): Boolean =
@@ -950,6 +958,9 @@ object CaptureSet:
950958 abstract class DerivedVar (owner : Symbol , initialElems : Refs )(using @ constructorOnly ctx : Context )
951959 extends Var (owner, initialElems):
952960
961+ override def levelOK (elem : Capability )(using Context ): Boolean =
962+ true
963+
953964 // For debugging: A trace where a set was created. Note that logically it would make more
954965 // sense to place this variable in Mapped, but that runs afoul of the initialization checker.
955966 // val stack = if debugSets && this.isInstanceOf[Mapped] then (new Throwable).getStackTrace().take(20) else null
@@ -995,6 +1006,10 @@ object CaptureSet:
9951006 (val source : Var , val bimap : BiTypeMap , initialElems : Refs )(using @ constructorOnly ctx : Context )
9961007 extends DerivedVar (source.owner, initialElems):
9971008
1009+ if debugVars && id == debugTarget then
1010+ println(i " variable $id is derived from $source" )
1011+ assert(false )
1012+
9981013 override def tryInclude (elem : Capability , origin : CaptureSet )(using Context , VarState ): Boolean =
9991014 if origin eq source then
10001015 val mappedElem = bimap.mapCapability(elem)
0 commit comments