Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Illegal aliasing with arrays update not caught #1218

Closed
mario-bucev opened this issue Dec 22, 2021 · 0 comments · Fixed by #1252
Closed

Illegal aliasing with arrays update not caught #1218

mario-bucev opened this issue Dec 22, 2021 · 0 comments · Fixed by #1252
Labels

Comments

@mario-bucev
Copy link
Collaborator

mario-bucev commented Dec 22, 2021

The following code should be rejected, but isn't:

object TestAlias {
  case class B(var x: Int)

  def test(arr: Array[B]): Unit = {
    require(arr.length >= 2)
    val arr2 = arr.updated(1, B(42))
    f(arr(0), arr2(0)) // Illegal aliasing not caught 
  }

  def f(b1: B, b2: B): Unit = {
    val x1 = b1.x
    b2.x = 50
    assert(b1.x == x1)
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants