Skip to content

Commit 9f40649

Browse files
committed
Allow SharableCapablity anywhere on a path
1 parent 65a1301 commit 9f40649

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

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

+10
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,16 @@ extension (tp: Type)
285285
case tp1: TypeRef if !tp1.symbol.is(Param) => tp1.prefix.pathRoot
286286
case tp1 => tp1
287287

288+
/** The first element of a path type, but stop at references extending
289+
* SharableCapability
290+
*/
291+
final def pathRootOrShared(using Context): Type =
292+
if tp.derivesFrom(defn.Caps_SharedCapability) then tp
293+
else tp.dealias match
294+
case tp1: TermRef if tp1.symbol.maybeOwner.isClass => tp1.prefix.pathRoot
295+
case tp1: TypeRef if !tp1.symbol.is(Param) => tp1.prefix.pathRoot
296+
case tp1 => tp1
297+
288298
/** If this part starts with `C.this`, the class `C`.
289299
* Otherwise, if it starts with a reference `r`, `r`'s owner.
290300
* Otherwise NoSymbol.

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ class SepChecker(checker: CheckCaptures.CheckerAPI) extends tpd.TreeTraverser:
410410
val badParams = mutable.ListBuffer[Symbol]()
411411
def currentOwner = role.dclSym.orElse(ctx.owner)
412412
for hiddenRef <- prune(refsToCheck, tpe, role) do
413-
val proot = hiddenRef.pathRoot
413+
val proot = hiddenRef.pathRootOrShared
414414
if !proot.widen.derivesFrom(defn.Caps_SharedCapability) then
415415
proot match
416416
case ref: TermRef =>
@@ -448,7 +448,7 @@ class SepChecker(checker: CheckCaptures.CheckerAPI) extends tpd.TreeTraverser:
448448
role match
449449
case _: TypeRole.Argument | _: TypeRole.Qualifier =>
450450
for ref <- refsToCheck do
451-
if !ref.derivesFrom(defn.Caps_SharedCapability) then
451+
if !ref.pathRootOrShared.derivesFrom(defn.Caps_SharedCapability) then
452452
consumed.put(ref, pos)
453453
case _ =>
454454
end checkConsumedRefs

0 commit comments

Comments
 (0)