@@ -232,7 +232,9 @@ extension (tp: Type)
232232 case tp @ ReachCapability (_) =>
233233 tp.singletonCaptureSet
234234 case ReadOnlyCapability (ref) =>
235- ref.deepCaptureSet(includeTypevars).readOnly
235+ val refDcs = ref.deepCaptureSet(includeTypevars)
236+ if refDcs.isConst then CaptureSet (refDcs.elems.map(_.readOnly))
237+ else refDcs // this case should not happen for correct programs
236238 case tp : SingletonCaptureRef if tp.isTrackableRef =>
237239 tp.reach.singletonCaptureSet
238240 case _ =>
@@ -283,10 +285,20 @@ extension (tp: Type)
283285 * are of the form this.C but their pathroot is still this.C, not this.
284286 */
285287 final def pathRoot (using Context ): Type = tp.dealias match
286- case tp1 : NamedType if tp1.symbol.maybeOwner.isClass && ! tp1.symbol.is( TypeParam ) =>
287- tp1.prefix.pathRoot
288+ case tp1 : TermRef if tp1.symbol.maybeOwner.isClass => tp1.prefix.pathRoot
289+ case tp1 : TypeRef if ! tp1.symbol.is( Param ) => tp1.prefix.pathRoot
288290 case tp1 => tp1
289291
292+ /** The first element of a path type, but stop at references extending
293+ * SharedCapability.
294+ */
295+ final def pathRootOrShared (using Context ): Type =
296+ if tp.derivesFromSharedCapability then tp
297+ else tp.dealias match
298+ case tp1 : TermRef if tp1.symbol.maybeOwner.isClass => tp1.prefix.pathRoot
299+ case tp1 : TypeRef if ! tp1.symbol.is(Param ) => tp1.prefix.pathRoot
300+ case tp1 => tp1
301+
290302 /** If this part starts with `C.this`, the class `C`.
291303 * Otherwise, if it starts with a reference `r`, `r`'s owner.
292304 * Otherwise NoSymbol.
0 commit comments