diff --git a/compiler/src/dotty/tools/dotc/typer/Namer.scala b/compiler/src/dotty/tools/dotc/typer/Namer.scala index 02a55be9ea5a..fc7067c7b45e 100644 --- a/compiler/src/dotty/tools/dotc/typer/Namer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Namer.scala @@ -995,8 +995,12 @@ class Namer { typer: Typer => end if } + /** Imply `update` for consume methods in Mutable classes */ private def normalizeFlags(denot: SymDenotation)(using Context): Unit = - if denot.is(Method) && denot.hasAnnotation(defn.ConsumeAnnot) then + if denot.is(Method) + && denot.hasAnnotation(defn.ConsumeAnnot) + && denot.owner.derivesFrom(defn.Caps_Mutable) + then denot.setFlag(Mutable) /** Intentionally left without `using Context` parameter. We need diff --git a/docs/_docs/reference/experimental/capture-checking/separation-checking.md b/docs/_docs/reference/experimental/capture-checking/separation-checking.md index 7fcb35658679..52b80a9e5782 100644 --- a/docs/_docs/reference/experimental/capture-checking/separation-checking.md +++ b/docs/_docs/reference/experimental/capture-checking/separation-checking.md @@ -195,7 +195,7 @@ Buffers in Scala's standard library use a single-argument method `+=` instead of class Buffer[T] extends Mutable: consume def +=(x: T): Buffer[T]^ = this // ok ``` -`consume` on a method implies `update`, so there's no need to label `+=` separately as an update method. Then we can write +`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 ```scala val b = Buffer[Int]() += 1 += 2 val c = b += 3 diff --git a/tests/pos-custom-args/captures/i24372.scala b/tests/pos-custom-args/captures/i24372.scala new file mode 100644 index 000000000000..76c3d85e08fe --- /dev/null +++ b/tests/pos-custom-args/captures/i24372.scala @@ -0,0 +1,2 @@ +trait Foo extends caps.ExclusiveCapability: + consume def sink: Unit = ()