@@ -655,8 +655,15 @@ object CaptureSet:
655
655
inline val debugVars = false
656
656
inline val debugTarget = 1745
657
657
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 :
660
667
661
668
override def owner = initialOwner
662
669
@@ -682,7 +689,7 @@ object CaptureSet:
682
689
protected var myElems : Refs = initialElems
683
690
684
691
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" )
686
693
assert(false )
687
694
688
695
def elems : Refs = myElems
@@ -828,15 +835,16 @@ object CaptureSet:
828
835
829
836
def levelOK (elem : Capability )(using Context ): Boolean = elem match
830
837
case elem @ ResultCap (binder) =>
831
- rootLimit == null && ( this . isInstanceOf [ BiMapped ] || isPartOf(binder.resType) )
838
+ rootLimit == null && isPartOf(binder.resType)
832
839
case GlobalCap =>
833
840
rootLimit == null
834
841
case elem : ParamRef =>
835
- this . isInstanceOf [ BiMapped ] || isPartOf(elem.binder.resType)
842
+ isPartOf(elem.binder.resType)
836
843
case _ =>
837
844
if owner.exists then
838
845
val elemVis = elem.visibility
839
846
! elemVis.isProperlyContainedIn(owner)
847
+ || nestedOK && elemVis.owner == owner
840
848
else true
841
849
842
850
def addDependent (cs : CaptureSet )(using Context , VarState ): Boolean =
@@ -950,6 +958,9 @@ object CaptureSet:
950
958
abstract class DerivedVar (owner : Symbol , initialElems : Refs )(using @ constructorOnly ctx : Context )
951
959
extends Var (owner, initialElems):
952
960
961
+ override def levelOK (elem : Capability )(using Context ): Boolean =
962
+ true
963
+
953
964
// For debugging: A trace where a set was created. Note that logically it would make more
954
965
// sense to place this variable in Mapped, but that runs afoul of the initialization checker.
955
966
// val stack = if debugSets && this.isInstanceOf[Mapped] then (new Throwable).getStackTrace().take(20) else null
@@ -995,6 +1006,10 @@ object CaptureSet:
995
1006
(val source : Var , val bimap : BiTypeMap , initialElems : Refs )(using @ constructorOnly ctx : Context )
996
1007
extends DerivedVar (source.owner, initialElems):
997
1008
1009
+ if debugVars && id == debugTarget then
1010
+ println(i " variable $id is derived from $source" )
1011
+ assert(false )
1012
+
998
1013
override def tryInclude (elem : Capability , origin : CaptureSet )(using Context , VarState ): Boolean =
999
1014
if origin eq source then
1000
1015
val mappedElem = bimap.mapCapability(elem)
0 commit comments