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

Type encoding erases error[Nothing] to () #817

Closed
gsps opened this issue Aug 3, 2020 · 2 comments · Fixed by #818
Closed

Type encoding erases error[Nothing] to () #817

gsps opened this issue Aug 3, 2020 · 2 comments · Fixed by #818

Comments

@gsps
Copy link
Contributor

gsps commented Aug 3, 2020

In the following example

import stainless.lang._

object Error {
  def foo(x: Int): Unit = {
    if (x == 0) {
      error[Nothing]("Panic")
    } else {
      ()
    }
  }
}

type encoding is triggered, because we instantiated error at Nothing. After type encoding, that tree has been replaced by just (), so we miss the counterexample x == 0.

This presumably has something to do with the Unit type, in particular, as I couldn't recreate the same problematic behavior using any other primitive type. The problem also doesn't occur when we explicitly instantiate at the right type (error[Unit]).

@gsps
Copy link
Contributor Author

gsps commented Aug 3, 2020

It seems that when "unwrapping" an encoded expression e to Unit, we simply drop the expression and replace it by () at the moment (https://github.com/epfl-lara/stainless/blob/master/core/src/main/scala/stainless/extraction/oo/TypeEncoding.scala#L147). I suppose we should instead emit { e; () }, @samarion ?

@samarion
Copy link
Member

samarion commented Aug 3, 2020

Indeed, sounds like a reasonable fix.

You'll have to use a let-binding for e though, we don't have blocks at that point anymore.

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

Successfully merging a pull request may close this issue.

2 participants