diff --git a/compiler/src/dotty/tools/dotc/ast/untpd.scala b/compiler/src/dotty/tools/dotc/ast/untpd.scala index b86734afcc0a..bcdbbbfa73dd 100644 --- a/compiler/src/dotty/tools/dotc/ast/untpd.scala +++ b/compiler/src/dotty/tools/dotc/ast/untpd.scala @@ -525,7 +525,7 @@ object untpd extends Trees.Instance[Untyped] with UntypedTreeInfo { def makeRetaining(parent: Tree, refs: List[Tree], annotName: TypeName)(using Context): Annotated = Annotated(parent, New(scalaAnnotationDot(annotName), List(refs))) - def makeCapsOf(tp: Tree)(using Context): Tree = + def makeCapsOf(tp: RefTree)(using Context): Tree = TypeApply(Select(scalaDot(nme.caps), nme.capsOf), tp :: Nil) def makeCapsBound()(using Context): Tree = diff --git a/compiler/src/dotty/tools/dotc/cc/CaptureOps.scala b/compiler/src/dotty/tools/dotc/cc/CaptureOps.scala index 79cc7d136e45..aad6ca8ddeac 100644 --- a/compiler/src/dotty/tools/dotc/cc/CaptureOps.scala +++ b/compiler/src/dotty/tools/dotc/cc/CaptureOps.scala @@ -194,8 +194,7 @@ extension (tp: Type) true case tp: TermRef => ((tp.prefix eq NoPrefix) - || tp.symbol.isField && !tp.symbol.isStatic && ( - tp.prefix.isThisTypeOf(tp.symbol.owner) || tp.prefix.isTrackableRef) + || tp.symbol.isField && !tp.symbol.isStatic && tp.prefix.isTrackableRef || tp.isRootCapability ) && !tp.symbol.isOneOf(UnstableValueFlags) case tp: TypeRef => diff --git a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala index 96f09a0d6214..a123291b2939 100644 --- a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala +++ b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala @@ -1548,22 +1548,20 @@ object Parsers { case _ => None } - /** CaptureRef ::= (ident | `this`) [`*` | `^`] + /** CaptureRef ::= SimpleRef { `.` id } [`*` | `^`] */ def captureRef(): Tree = - val ref = singleton() + val ref = dotSelectors(simpleRef()) if isIdent(nme.raw.STAR) then in.nextToken() atSpan(startOffset(ref)): PostfixOp(ref, Ident(nme.CC_REACH)) else if isIdent(nme.UPARROW) then in.nextToken() - def toTypeSel(r: Tree): Tree = r match - case id: Ident => cpy.Ident(id)(id.name.toTypeName) - case Select(qual, id) => Select(qual, id.toTypeName) - case _ => r atSpan(startOffset(ref)): - makeCapsOf(toTypeSel(ref)) + convertToTypeId(ref) match + case ref: RefTree => makeCapsOf(ref) + case ref => ref else ref /** CaptureSet ::= `{` CaptureRef {`,` CaptureRef} `}` -- under captureChecking