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

AntiAliasing not updating targets for val fields #1487

Open
mario-bucev opened this issue Nov 20, 2023 · 2 comments
Open

AntiAliasing not updating targets for val fields #1487

mario-bucev opened this issue Nov 20, 2023 · 2 comments
Assignees

Comments

@mario-bucev
Copy link
Collaborator

The following snippet is marked as invalid even though it is not:

import stainless.lang._
import stainless.annotation._

object VarVarBinks {
  sealed trait OptionMut[@mutable T] {
    def isDefined: Boolean = this match {
      case SomeMut(_) => true
      case NoneMut() => false
    }
    def get: T = {
      require(isDefined)
      this match {
        case SomeMut(v) => v
      }
    }
  }
  // Note: v is not a var!
  case class SomeMut[@mutable T](v: T) extends OptionMut[T]
  case class NoneMut[@mutable T]() extends OptionMut[T]

  case class C1(var f2: OptionMut[C2])
  case class C2(var f3: OptionMut[C3])
  case class C3(var v: BigInt)

  def test(x: BigInt): BigInt = {
    val c1 = C1(NoneMut())
    c1.f2 = SomeMut(C2(NoneMut()))
    c1.f2.get.f3 = SomeMut(C3(x))
    c1.f2.get.f3.get.v // precond to f3.get is invalid
  }
}

This is due to the field of SomeMut (v) being a val (declaring it a var makes the last expression go through as expected).
It seems that AntiAliasing is not correctly handling the update for c1.f2.get.f3 due to v not being a var.

@mario-bucev mario-bucev self-assigned this Nov 20, 2023
@vkuncak
Copy link
Collaborator

vkuncak commented Dec 5, 2023

@mario-bucev How often do we actually want a class parameterized by a mutable type but using val to refer to it?

@mario-bucev
Copy link
Collaborator Author

Not very often but I think this OptionMut/SomeMut is one of the rarest case.

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

No branches or pull requests

2 participants