Skip to content

Commit 8cd7a5f

Browse files
authored
Revert "Fix handling paths extending SharedCapability" (#22569)
Reverts #22564
2 parents a340ae9 + 0818005 commit 8cd7a5f

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

compiler/src/dotty/tools/dotc/cc/CaptureOps.scala

+15-3
Original file line numberDiff line numberDiff line change
@@ -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.

compiler/src/dotty/tools/dotc/cc/SepCheck.scala

+4-3
Original file line numberDiff line numberDiff line change
@@ -537,8 +537,9 @@ class SepCheck(checker: CheckCaptures.CheckerAPI) extends tpd.TreeTraverser:
537537
val badParams = mutable.ListBuffer[Symbol]()
538538
def currentOwner = role.dclSym.orElse(ctx.owner)
539539
for hiddenRef <- prune(refsToCheck, tpe, role) do
540-
if !hiddenRef.derivesFromSharedCapability then
541-
hiddenRef.pathRoot match
540+
val proot = hiddenRef.pathRootOrShared
541+
if !proot.widen.derivesFromSharedCapability then
542+
proot match
542543
case ref: TermRef =>
543544
val refSym = ref.symbol
544545
if currentOwner.enclosingMethodOrClass.isProperlyContainedIn(refSym.maybeOwner.enclosingMethodOrClass) then
@@ -574,7 +575,7 @@ class SepCheck(checker: CheckCaptures.CheckerAPI) extends tpd.TreeTraverser:
574575
role match
575576
case _: TypeRole.Argument | _: TypeRole.Qualifier =>
576577
for ref <- refsToCheck do
577-
if !ref.derivesFromSharedCapability then
578+
if !ref.pathRootOrShared.derivesFromSharedCapability then
578579
consumed.put(ref, pos)
579580
case _ =>
580581
end checkConsumedRefs

0 commit comments

Comments
 (0)