Skip to content

Commit b2b7dd4

Browse files
committed
Imply update only for consume methods in Mutable classes
1 parent 9ba8854 commit b2b7dd4

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

compiler/src/dotty/tools/dotc/typer/Namer.scala

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -995,8 +995,12 @@ class Namer { typer: Typer =>
995995
end if
996996
}
997997

998+
/** Imply `update` for consume methods in Mutable classes */
998999
private def normalizeFlags(denot: SymDenotation)(using Context): Unit =
999-
if denot.is(Method) && denot.hasAnnotation(defn.ConsumeAnnot) then
1000+
if denot.is(Method)
1001+
&& denot.hasAnnotation(defn.ConsumeAnnot)
1002+
&& denot.owner.derivesFrom(defn.Caps_Mutable)
1003+
then
10001004
denot.setFlag(Mutable)
10011005

10021006
/** Intentionally left without `using Context` parameter. We need

docs/_docs/reference/experimental/capture-checking/separation-checking.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ Buffers in Scala's standard library use a single-argument method `+=` instead of
195195
class Buffer[T] extends Mutable:
196196
consume def +=(x: T): Buffer[T]^ = this // ok
197197
```
198-
`consume` on a method implies `update`, so there's no need to label `+=` separately as an update method. Then we can write
198+
`consume` on a method in a `Mutable` class implies `update`, so there's no need to label `+=` separately as an update method. Then we can write
199199
```scala
200200
val b = Buffer[Int]() += 1 += 2
201201
val c = b += 3
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
trait Foo extends caps.ExclusiveCapability:
2+
consume def sink: Unit = ()

0 commit comments

Comments
 (0)