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

Ghost checker should disallow pattern matching on a ghost field #460

Open
romac opened this issue Mar 7, 2019 · 3 comments
Open

Ghost checker should disallow pattern matching on a ghost field #460

romac opened this issue Mar 7, 2019 · 3 comments

Comments

@romac
Copy link
Member

romac commented Mar 7, 2019

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

object GhostMatch {

  case class Foo(@ghost value: Option[BigInt])

  def nonGhostMatch(foo: Foo) = {
    foo match { // should fail because foo.value will not exist at runtime
      case Foo(Some(a)) => true
      case Foo(_) => false
    }
  }

  @ghost
  def ghostMatch(foo: Foo) = {
    foo match { // this is okay because we are in ghost context
      case Foo(Some(a)) => true
      case Foo(_) => false
    }
  }
}
@romac romac added the bug label Mar 7, 2019
@romac romac added this to the Scala Days milestone May 15, 2019
@romac romac modified the milestones: 0.3, 0.4 Jun 26, 2019
@romac romac modified the milestone: 0.6 Sep 19, 2019
@romac romac removed this from the 0.6 milestone Nov 7, 2019
@vkuncak vkuncak added the ghost label Sep 11, 2021
@vkuncak
Copy link
Collaborator

vkuncak commented Sep 11, 2021

Confirmed still reproducible on Version: 0.9.0-34-g88308df

@vkuncak
Copy link
Collaborator

vkuncak commented Sep 11, 2021

This minor variant breaks --genc:

import stainless.lang._
import stainless.annotation._
object GhostMatch {
  case class Foo(@ghost value: Option[Int])
  def nonGhostMatch(foo: Foo): Int = {
    foo match { // should fail because foo.value will not exist at runtime
      case Foo(Some(a)) => 1
      case Foo(_) => 0
    }
  }
  @ghost
  def ghostMatch(foo: Foo) = {
    foo match { // this is okay because we are in ghost context
      case Foo(Some(a)) => true
      case Foo(_) => false
    }
  }
  @cCode.export
  def test(): Int = {
    nonGhostMatch(Foo(Some[Int](3)))
  }
  @extern
  def main(args: Array[String]): Unit = test  
}

@jad-hamza
Copy link
Contributor

GenC itself doesn't do ghost checks (only ghost elimination). The checks are done by the GhostChecker I think even before the Stainless pipeline.

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

3 participants