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

Error reporting from alias analysis #1513

Open
vkuncak opened this issue Apr 29, 2024 · 0 comments
Open

Error reporting from alias analysis #1513

vkuncak opened this issue Apr 29, 2024 · 0 comments
Assignees

Comments

@vkuncak
Copy link
Collaborator

vkuncak commented Apr 29, 2024

In Version: 0.9.8.2-24-g54399d0-SNAPSHOT,
this program:

object Test {
  def setFirst(a: Array[Int]): Array[Int] = 
    require(a.size > 0)
    a(0) = 1    
    a

  def test =
    val a = Array.fill(10)(0)
    val b = setFirst(a)
    b(0) = 2
}

gives a low level error message:

[ Error  ] Test.scala:9:13: Couldn't apply effect ReplacementEffect(b(0)) on expression var res: (Array[Int], Array[Int]) = setFirst(a)        
[ Error  ] a = @DropVCs @DropVCs res._2.asInstanceOf[Array[Int]]
[ Error  ] a = @DropVCs @DropVCs a.asInstanceOf[Array[Int]]
[ Error  ] res._1
               val b = setFirst(a)
                       ^^^^^^^^^^^

whereas assigning to the other aliased variable:

object Test {
  def setFirst(a: Array[Int]): Array[Int] = 
    require(a.size > 0)
    a(0) = 1    
    a

  def test =
    val a = Array.fill(10)(0)
    val b = setFirst(a)
    a(0) = 2
}

gives:

[ Error  ] Test.scala:9:5: Unsupported `val` definition in AntiAliasing
[ Error  ] The following variables of mutable types are shared between the binding and the body:
[ Error  ]   a: Array[Int]
               val b = setFirst(a)
               ^^^^^^^^^^^^^^^^^^^

Finally,

object Test {
  def setFirst(a: Array[Int]): Array[Int] = 
    require(a.size > 0)
    a(0) = 1    
    a

  def test =
    val a = Array.fill(10)(0)
    val b = setFirst(a)
  ()
}

actually passes, which is sort of nice, but makes things possibly hard to understand.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants