@@ -2163,7 +2163,7 @@ object Types {
21632163 }
21642164
21652165 /** A trait for references in CaptureSets. These can be NamedTypes, ThisTypes or ParamRefs */
2166- trait CaptureRef extends SingletonType :
2166+ trait CaptureRef extends TypeProxy , ValueType :
21672167 private var myCaptureSet : CaptureSet | Null = uninitialized
21682168 private var myCaptureSetRunId : Int = NoRunId
21692169 private var mySingletonCaptureSet : CaptureSet .Const | Null = null
@@ -2175,9 +2175,9 @@ object Types {
21752175 isTrackableRef && (isRootCapability || ! captureSetOfInfo.isAlwaysEmpty)
21762176
21772177 /** Is this a reach reference of the form `x*`? */
2178- def isReach (using Context ): Boolean = false // overridden in TermRef
2178+ def isReach (using Context ): Boolean = false // overridden in AnnotatedType
21792179
2180- def stripReach (using Context ): CaptureRef = this // overridden in TermRef
2180+ def stripReach (using Context ): CaptureRef = this // overridden in AnnotatedType
21812181
21822182 /** Is this reference the generic root capability `cap` ? */
21832183 def isRootCapability (using Context ): Boolean = false
@@ -2214,6 +2214,8 @@ object Types {
22142214
22152215 end CaptureRef
22162216
2217+ trait SingletonCaptureRef extends SingletonType , CaptureRef
2218+
22172219 /** A trait for types that bind other types that refer to them.
22182220 * Instances are: LambdaType, RecType.
22192221 */
@@ -2877,7 +2879,7 @@ object Types {
28772879 */
28782880 abstract case class TermRef (override val prefix : Type ,
28792881 private var myDesignator : Designator )
2880- extends NamedType , ImplicitRef , CaptureRef {
2882+ extends NamedType , ImplicitRef , SingletonCaptureRef {
28812883
28822884 type ThisType = TermRef
28832885 type ThisName = TermName
@@ -2913,21 +2915,12 @@ object Types {
29132915 || symbol.is(ParamAccessor ) && (prefix eq symbol.owner.thisType)
29142916 || isRootCapability
29152917 ) && ! symbol.isOneOf(UnstableValueFlags )
2916- || isReach
2917-
2918- override def isReach (using Context ): Boolean =
2919- name == nme.CC_REACH && symbol == defn.Any_ccReach
2920-
2921- override def stripReach (using Context ): CaptureRef =
2922- if isReach then prefix.asInstanceOf [CaptureRef ] else this
29232918
29242919 override def isRootCapability (using Context ): Boolean =
29252920 name == nme.CAPTURE_ROOT && symbol == defn.captureRoot
29262921
29272922 override def normalizedRef (using Context ): CaptureRef =
2928- if isReach then TermRef (stripReach.normalizedRef, name, denot)
2929- else if isTrackableRef then symbol.termRef
2930- else this
2923+ if isTrackableRef then symbol.termRef else this
29312924 }
29322925
29332926 abstract case class TypeRef (override val prefix : Type ,
@@ -3066,7 +3059,8 @@ object Types {
30663059 * Note: we do not pass a class symbol directly, because symbols
30673060 * do not survive runs whereas typerefs do.
30683061 */
3069- abstract case class ThisType (tref : TypeRef ) extends CachedProxyType , CaptureRef {
3062+ abstract case class ThisType (tref : TypeRef )
3063+ extends CachedProxyType , SingletonCaptureRef {
30703064 def cls (using Context ): ClassSymbol = tref.stableInRunSymbol match {
30713065 case cls : ClassSymbol => cls
30723066 case _ if ctx.mode.is(Mode .Interactive ) => defn.AnyClass // was observed to happen in IDE mode
@@ -4679,7 +4673,8 @@ object Types {
46794673 /** Only created in `binder.paramRefs`. Use `binder.paramRefs(paramNum)` to
46804674 * refer to `TermParamRef(binder, paramNum)`.
46814675 */
4682- abstract case class TermParamRef (binder : TermLambda , paramNum : Int ) extends ParamRef , CaptureRef {
4676+ abstract case class TermParamRef (binder : TermLambda , paramNum : Int )
4677+ extends ParamRef , SingletonCaptureRef {
46834678 type BT = TermLambda
46844679 def kindString : String = " Term"
46854680 def copyBoundType (bt : BT ): Type = bt.paramRefs(paramNum)
@@ -5386,7 +5381,7 @@ object Types {
53865381 // ----- Annotated and Import types -----------------------------------------------
53875382
53885383 /** An annotated type tpe @ annot */
5389- abstract case class AnnotatedType (parent : Type , annot : Annotation ) extends CachedProxyType , ValueType {
5384+ abstract case class AnnotatedType (parent : Type , annot : Annotation ) extends CachedProxyType , CaptureRef {
53905385
53915386 override def underlying (using Context ): Type = parent
53925387
@@ -5415,6 +5410,23 @@ object Types {
54155410 isRefiningCache
54165411 }
54175412
5413+ override def isTrackableRef (using Context ) =
5414+ isReach && parent.isTrackableRef
5415+
5416+ /** Is this a reach reference of the form `x*`? */
5417+ override def isReach (using Context ): Boolean =
5418+ annot.symbol == defn.ReachCapabilityAnnot
5419+
5420+ override def stripReach (using Context ): SingletonCaptureRef =
5421+ (if isReach then parent else this ).asInstanceOf [SingletonCaptureRef ]
5422+
5423+ override def normalizedRef (using Context ): CaptureRef =
5424+ if isReach then AnnotatedType (stripReach.normalizedRef, annot) else this
5425+
5426+ override def captureSet (using Context ): CaptureSet =
5427+ if isReach then super .captureSet
5428+ else CaptureSet .ofType(this , followResult = false )
5429+
54185430 // equals comes from case class; no matching override is needed
54195431
54205432 override def computeHash (bs : Binders ): Int =
0 commit comments