Skip to content

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

@bracevac

Description

@bracevac

Compiler version

Current nightly.

Minimized code

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()
  val m: Matrix^ = Matrix(() => 42)
  val m2: Matrix^ = Matrix(() => m.run())
  val m3: Matrix^ = Matrix(() => r.get())

  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(m2) // ok
  g(m3) // ok

Output

The compiler happily accepts this.

Expectation

It shouldn't!

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions