Skip to content

Commit c427246

Browse files
committed
Follow singleton types when determining exclusivityInContext
1 parent 5b0f56d commit c427246

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,14 @@ object Mutability:
104104
if tp.derivesFrom(defn.Caps_Stateful)
105105
then ctx.owner.inExclusivePartOf(tp.cls)
106106
else Exclusivity.OK
107-
case tp @ TermRef(prefix: Capability, _) =>
108-
prefix.exclusivityInContext(required).andAlso(tp.exclusivity(required))
107+
case tp: TermRef =>
108+
tp.info match
109+
case tp1: SingletonType => tp1.exclusivityInContext(required)
110+
case _ =>
111+
val preEx = tp.prefix match
112+
case prefix: Capability => prefix.exclusivityInContext(required)
113+
case _ => Exclusivity.OK
114+
preEx.andAlso(tp.exclusivity(required))
109115
case _ =>
110116
tp.exclusivity(required)
111117

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import caps.*
2+
trait A extends Stateful:
3+
def f() = /* read-only f */
4+
val ref: this.type = this
5+
this.g()
6+
ref.g()
7+
8+
update def g() = ???

0 commit comments

Comments
 (0)