@@ -192,25 +192,34 @@ extension (tp: Type)
192
192
case _ =>
193
193
tp
194
194
195
- /** The first element of this path type. Note that class parameter references
196
- * are of the form this.C but their pathroot is still this.C, not this.
195
+ /** The first element of this path type, skipping selections
196
+ * and qualifiers. Note that class parameter references are of
197
+ * the form this.C but their pathroot is still this.C, not this.
197
198
*/
198
- final def pathRoot (using Context ): Type = tp.dealias match
199
- case tp1 : NamedType =>
200
- if tp1.symbol.maybeOwner.isClass && tp1.symbol != defn.captureRoot && ! tp1.symbol.is(TypeParam ) then
201
- tp1.prefix match
202
- case pre : CaptureRef => pre.pathRoot
203
- case _ => tp1
204
- else tp1
205
- case tp1 => tp1
206
-
207
- /** If this part starts with `C.this`, the class `C`.
208
- * Otherwise, if it starts with a reference `r`, `r`'s owner.
209
- * Otherwise NoSymbol.
199
+ final def pathRoot (using Context ): Type = tp match
200
+ case root(_) => tp
201
+ case QualifiedCapability (tp1) => tp1.pathRoot
202
+ case _ => tp.dealias match
203
+ case tp1 : NamedType =>
204
+ if tp1.symbol.maybeOwner.isClass && ! tp1.symbol.is(TypeParam ) then
205
+ tp1.prefix match
206
+ case pre : CaptureRef => pre.pathRoot
207
+ case _ => tp1
208
+ else tp1
209
+ case tp1 => tp1
210
+
211
+ /** The logical owner of the root of this class:
212
+ * - If this path starts with `C.this`, the class `C`.
213
+ * - If it starts with a reference `r`, `r`'s owner.
214
+ * - If it starts with cap, the `scala.caps` package class.
215
+ * - If it starts with a fresh instance, its owner.
216
+ * - If it starts with a ParamRef or a result root, NoSymbol.
210
217
*/
211
218
final def pathOwner (using Context ): Symbol = pathRoot match
219
+ case tp1 : TermRef if tp1.isCap => defn.CapsModule .moduleClass
212
220
case tp1 : NamedType => tp1.symbol.owner
213
221
case tp1 : ThisType => tp1.cls
222
+ case tp1 @ root.Fresh (_) => tp1.ccOwner
214
223
case _ => NoSymbol
215
224
216
225
final def isParamPath (using Context ): Boolean = tp.dealias match
0 commit comments