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

MethodLifting reporting when subclasses have preconditions #1511

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

MethodLifting reporting when subclasses have preconditions #1511

vkuncak opened this issue Apr 22, 2024 · 0 comments

Comments

@vkuncak
Copy link
Collaborator

vkuncak commented Apr 22, 2024

MethodLifting creates a method in the superclass. When the methods in subclasses have preconditions, this causes a message that may be hard to understand. Take this example:

sealed trait IntList:
  def isEmpty: Boolean
  def head: Int   
  def tail: IntList

case class IntNil() extends IntList:
  def isEmpty: Boolean = true

  def head =
    require(false)
    ???

  def tail =
    require(false)
    ???

case class IntCons(head: Int, tail: IntList) extends IntList:
  def isEmpty: Boolean = false

A failing VC we get looks like this:

IntListHm.scala:4:7:   head     precond. (call head(({   assert(thiss.isInstanceOf[I... (require 2/2))  invalid           nativez3  0.0 
warning:  - Result for 'precond. (call head(({   assert(thiss.isInstanceOf[I... (require 2/2))' VC for head @4:7:
warning: thiss.isInstanceOf[IntCons]
IntListHm.scala:4:7: warning:  => INVALID
             def head: Int   
                 ^
warning: Found counter-example:
warning:   thiss: IntList -> IntNil()

A friendly error message would be something like:

require of IntList.head implies the require of IntNil.head
@vkuncak vkuncak changed the title MethodLifting should when subclasses have preconditions MethodLifting reporting when subclasses have preconditions Apr 29, 2024
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

1 participant