Skip to content

Commit

Permalink
Allow SharableCapablity anywhere on a path
Browse files Browse the repository at this point in the history
  • Loading branch information
odersky committed Feb 6, 2025
1 parent 2bf473d commit 7b3d3f4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
10 changes: 10 additions & 0 deletions compiler/src/dotty/tools/dotc/cc/CaptureOps.scala
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,16 @@ extension (tp: Type)
case tp1: TypeRef if !tp1.symbol.is(Param) => tp1.prefix.pathRoot
case tp1 => tp1

/** The first element of a path type, but stop at references extending
* SharableCapability
*/
final def pathRootOrShared(using Context): Type =
if tp.derivesFrom(defn.Caps_SharedCapability) then tp
else tp.dealias match
case tp1: TermRef if tp1.symbol.maybeOwner.isClass => tp1.prefix.pathRoot
case tp1: TypeRef if !tp1.symbol.is(Param) => tp1.prefix.pathRoot
case tp1 => tp1

/** If this part starts with `C.this`, the class `C`.
* Otherwise, if it starts with a reference `r`, `r`'s owner.
* Otherwise NoSymbol.
Expand Down
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/cc/SepCheck.scala
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ class SepChecker(checker: CheckCaptures.CheckerAPI) extends tpd.TreeTraverser:
val badParams = mutable.ListBuffer[Symbol]()
def currentOwner = role.dclSym.orElse(ctx.owner)
for hiddenRef <- prune(refsToCheck, tpe, role) do
val proot = hiddenRef.pathRoot
val proot = hiddenRef.pathRootOrShared
if !proot.widen.derivesFrom(defn.Caps_SharedCapability) then
proot match
case ref: TermRef =>
Expand Down Expand Up @@ -448,7 +448,7 @@ class SepChecker(checker: CheckCaptures.CheckerAPI) extends tpd.TreeTraverser:
role match
case _: TypeRole.Argument | _: TypeRole.Qualifier =>
for ref <- refsToCheck do
if !ref.derivesFrom(defn.Caps_SharedCapability) then
if !ref.pathRootOrShared.derivesFrom(defn.Caps_SharedCapability) then
consumed.put(ref, pos)
case _ =>
end checkConsumedRefs
Expand Down

0 comments on commit 7b3d3f4

Please sign in to comment.