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

Initializing assignments make iset/imap auto-ghost #5033

Closed
RustanLeino opened this issue Feb 1, 2024 · 0 comments · Fixed by #5041
Closed

Initializing assignments make iset/imap auto-ghost #5033

RustanLeino opened this issue Feb 1, 2024 · 0 comments · Fixed by #5041
Assignees
Labels
kind: bug Crashes, unsoundness, incorrect output, etc. If possible, add a `part:` label part: resolver Resolution and typechecking

Comments

@RustanLeino
Copy link
Collaborator

Dafny version

4.4.0

Code to produce this issue

method Test() {
  var s := {3, 3, 3, 5};
  var u := iset x | x in s; // BOGUS: this is making "u" auto-ghost

  var m := map[3 := true, 5 := false];
  var w := imap x | x in m :: true; // BOGUS: this is making "w" auto-ghost

  print u, w;
}

predicate LessThanFour(x: int) {
  x < 4
}

Command to run and resulting output

% dafny test.dfy
test.dfy(9,8): Error: ghost variables such as u are allowed only in specification contexts. u was inferred to be ghost based on its declaration or initialization. (ID: r_ghost_var_only_in_specifications)
test.dfy(9,11): Error: ghost variables such as w are allowed only in specification contexts. w was inferred to be ghost based on its declaration or initialization. (ID: r_ghost_var_only_in_specifications)
2 resolution/type errors detected in test.dfy

What happened?

The program should be compilable. However, the RHSs of the initializing assignments to u and w (which use iset/imap comprehensions where the "bounded pool" is coming from a collection, namely a set) are making those variables auto-ghost. This results in the errors shown above.

If the RHS expressions above are used in places other than initializing assignments, then Dafny correctly determines that they are compilable. This indicates that the bug lies in UsesSpecFeatures and that the similar (but different) method CheckIsCompilable is implemented correctly.

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

Mac

@RustanLeino RustanLeino added kind: bug Crashes, unsoundness, incorrect output, etc. If possible, add a `part:` label part: resolver Resolution and typechecking labels Feb 1, 2024
@RustanLeino RustanLeino self-assigned this Feb 1, 2024
RustanLeino added a commit to RustanLeino/dafny that referenced this issue Feb 1, 2024
keyboardDrummer pushed a commit that referenced this issue Feb 2, 2024
Fixes #5033
Fixes #5034
Fixes #5035

This PR allows more expressions as compiled (from issues #5033 and
#5034) and also adds some missing restrictions on uses of ghosts
(#5035), all having to do with set/iset/map/imap comprehensions.

### How has this been tested?

The tests from these Issues have been added to `DiscoverBounds.dfy` and
`DiscoverBoundsErrors.dfy`.

<small>By submitting this pull request, I confirm that my contribution
is made under the terms of the [MIT
license](https://github.com/dafny-lang/dafny/blob/master/LICENSE.txt).</small>
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 part: resolver Resolution and typechecking
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant