Skip to content

Purity and mutable types #24454

@Linyxus

Description

@Linyxus

Compiler version

main

Minimized code

import language.experimental.captureChecking
import language.experimental.separationChecking
import caps.{Mutable, freeze}

// A mutable ref and its immutable version
class Ref extends Mutable:
  private var data: Int = 0
  def get: Int = data
  update def set(x: Int): Unit = data = x
def allocRef(): Ref^ = Ref()
type IRef = Ref^{}

def main(): Unit =
  val a = allocRef()
  val t1: IRef = a  // should be error too, but ok
  val t2: Ref^{} = a  // error

Output

Only the last line has an error, but not the IRef line.

Expectation

Both line should be an error. They should morally be equivalent.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions