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

Definite-assignment in specification depends on implementation #6064

Open
RustanLeino opened this issue Jan 22, 2025 · 0 comments
Open

Definite-assignment in specification depends on implementation #6064

RustanLeino opened this issue Jan 22, 2025 · 0 comments
Labels
kind: bug Crashes, unsoundness, incorrect output, etc. If possible, add a `part:` label

Comments

@RustanLeino
Copy link
Collaborator

Dafny version

4.9.1

Code to produce this issue

method M0(b: bool) {
  var x: int;
  opaque
    ensures b ==> x == 8
  {
    if b {
      x := 8;
    }
  }
}

method M1(b: bool) {
  var x: int;
  opaque
    ensures b ==> x == 8
  {
    x := 8;
  }
}

Command to run and resulting output

% dafny verify test.dfy
test.dfy(4,18): Error: variable 'x', which is subject to definite-assignment rules, might be uninitialized here
  |
4 |     ensures b ==> x == 8 // as a spec, this is odd, because it could be evaluated in a context where x is not assigned
  |                   ^

What happened?

The specification of the opaque block in both of the methods above is

  opaque
    ensures b ==> x == 8

Specifications in Dafny (e.g., ensures clauses of methods and invariant clauses of loops) are checked for well-formedness _without regard of the implementation(except for gathering the syntactic assignment targets, which applies to both loops and opaque blocks, since these two can make local variables). However, of the methods above, an error is generated for methodM0but not forM1. The only difference between M0andM1` is the implementation (i.e., the body) of the opaque block.

The right thing to do is to check the well-formedness of the opaque block's specification without looking at the body. So, both of the methods above should generate an error.

What type of operating system are you experiencing the problem on?

Mac

@RustanLeino RustanLeino added the kind: bug Crashes, unsoundness, incorrect output, etc. If possible, add a `part:` label label Jan 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: bug Crashes, unsoundness, incorrect output, etc. If possible, add a `part:` label
Projects
None yet
Development

No branches or pull requests

1 participant