Skip to content

Conversation

@odersky
Copy link
Contributor

@odersky odersky commented Oct 31, 2025

Ensure that read-only methods don't use non-local exclusive capabilities

Fixes #24310

@Linyxus
Copy link
Contributor

Linyxus commented Nov 1, 2025

There is no "actual" data races in the original example so I suggest adding this example too:

import language.experimental.captureChecking
import language.experimental.separationChecking
import caps.*

class Ref extends Mutable:
  private var value: Int = 0
  def get(): Int = value
  update def set(v: Int): Unit = value = v

class Matrix(val f: () => Int) extends Mutable:
  self: Matrix^ =>
    def run() = f() // <- note the missing update
    update def add(): Unit = ()

@main def test =
  val r: Ref^ = Ref()
  def inc(): Int =
    val old = r.get()
    r.set(old + 1)
    old
  val m4: Matrix^ = Matrix(inc)

  def par(f1: () => Int, f2: () => Int): Unit =
    println(s"par results: ${f1()} and ${f2()}")

  def g(m: Matrix^): Unit =
    par(m.run, m.run) // <- should be rejected

  g(m4) // ok, but should not

@odersky odersky merged commit 569ad50 into scala:main Nov 2, 2025
51 checks passed
@odersky odersky deleted the fix-24310 branch November 2, 2025 12:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CC: Issue with Separation Checking and Non-Update Method of Mutable Class

3 participants