-
Notifications
You must be signed in to change notification settings - Fork 270
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Don't consider := * to be definite assignment for non-ghost vari…
…ables of a (00) type (#5024) Fixes #5023 ### Description Previously, the verifier allowed `:= *` to satisfy the definite-assignment obligation for any known-to-be-nonempty type, regardless of context. The fix is to use `(0)`, not `(00)`, for non-ghost assignments. <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>
- Loading branch information
1 parent
dcc302a
commit a5fd6f3
Showing
8 changed files
with
206 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
176 changes: 176 additions & 0 deletions
176
Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-5023.dfy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,176 @@ | ||
// RUN: %testDafnyForEachResolver --expect-exit-code=4 "%s" | ||
|
||
// ---------- compiled variables/fields ---------- | ||
|
||
module GhostWitness { | ||
type Five = x: int | x == 5 ghost witness 5 | ||
|
||
class ContainsFive { | ||
var five: Five | ||
|
||
constructor () { | ||
five := *; | ||
} // error: five not defined | ||
} | ||
|
||
method M() { | ||
var five: Five := *; | ||
var c := new ContainsFive(); | ||
|
||
if | ||
case true => | ||
print five, "\n"; // error: five used before defined | ||
case true => | ||
var x := | ||
var f: Five := five; // error: five used before defined | ||
assert f == 5; | ||
if f == 5 then 200 else 200/0; | ||
case true => | ||
print c.five, "\n"; | ||
} | ||
} | ||
|
||
module CompiledWitness { | ||
type Five = x: int | x == 5 witness 5 | ||
|
||
class ContainsFive { | ||
var five: Five | ||
|
||
constructor () { | ||
five := *; | ||
} | ||
} | ||
|
||
method M() { | ||
var five: Five := *; | ||
var c := new ContainsFive(); | ||
|
||
if | ||
case true => | ||
print five, "\n"; | ||
case true => | ||
var x := | ||
var f: Five := five; | ||
assert f == 5; | ||
if f == 5 then 200 else 200/0; | ||
case true => | ||
print c.five, "\n"; | ||
} | ||
} | ||
|
||
module NoWitness { | ||
type Five = x: int | x == 5 witness * | ||
|
||
class ContainsFive { | ||
var five: Five | ||
|
||
constructor () { | ||
five := *; | ||
} // error: five not defined | ||
} | ||
|
||
method M() { | ||
var five: Five := *; | ||
var c := new ContainsFive(); | ||
|
||
if | ||
case true => | ||
print five, "\n"; // error: five used before defined | ||
case true => | ||
var x := | ||
var f: Five := five; // error: five used before defined | ||
assert f == 5; | ||
if f == 5 then 200 else 200/0; | ||
case true => | ||
print c.five, "\n"; | ||
} | ||
} | ||
|
||
// ---------- ghost variables/fields ---------- | ||
|
||
module XGhostWitness { | ||
type Five = x: int | x == 5 ghost witness 5 | ||
|
||
class ContainsFive { | ||
ghost var five: Five | ||
|
||
constructor () { | ||
five := *; | ||
} | ||
} | ||
|
||
method M() returns (ghost g: int) { | ||
g := 0; | ||
ghost var five: Five := *; | ||
var c := new ContainsFive(); | ||
|
||
if | ||
case true => | ||
g := five; | ||
case true => | ||
ghost var x := | ||
var f: Five := five; | ||
assert f == 5; | ||
if f == 5 then 200 else 200/0; | ||
case true => | ||
g := c.five; | ||
} | ||
} | ||
|
||
module XCompiledWitness { | ||
type Five = x: int | x == 5 witness 5 | ||
|
||
class ContainsFive { | ||
ghost var five: Five | ||
|
||
constructor () { | ||
five := *; | ||
} | ||
} | ||
|
||
method M() returns (ghost g: int) { | ||
g := 0; | ||
ghost var five: Five := *; | ||
var c := new ContainsFive(); | ||
|
||
if | ||
case true => | ||
g := five; | ||
case true => | ||
ghost var x := | ||
var f: Five := five; | ||
assert f == 5; | ||
if f == 5 then 200 else 200/0; | ||
case true => | ||
g := c.five; | ||
} | ||
} | ||
|
||
module XNoWitness { | ||
type Five = x: int | x == 5 witness * | ||
|
||
class ContainsFive { | ||
ghost var five: Five | ||
|
||
constructor () { | ||
five := *; | ||
} // error: five not defined | ||
} | ||
|
||
method M() returns (ghost g: int) { | ||
g := 0; | ||
ghost var five: Five := *; | ||
var c := new ContainsFive(); | ||
|
||
if | ||
case true => | ||
g := five; // error: five used before defined | ||
case true => | ||
ghost var x := | ||
var f: Five := five; // error: five used before defined | ||
assert f == 5; | ||
if f == 5 then 200 else 200/0; | ||
case true => | ||
g := c.five; | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-5023.dfy.expect
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
git-issue-5023.dfy(13,4): Error: field 'five', which is subject to definite-assignment rules, might be uninitialized at this point in the constructor body | ||
git-issue-5023.dfy(22,12): Error: variable 'five', which is subject to definite-assignment rules, might be uninitialized here | ||
git-issue-5023.dfy(25,23): Error: variable 'five', which is subject to definite-assignment rules, might be uninitialized here | ||
git-issue-5023.dfy(69,4): Error: field 'five', which is subject to definite-assignment rules, might be uninitialized at this point in the constructor body | ||
git-issue-5023.dfy(78,12): Error: variable 'five', which is subject to definite-assignment rules, might be uninitialized here | ||
git-issue-5023.dfy(81,23): Error: variable 'five', which is subject to definite-assignment rules, might be uninitialized here | ||
git-issue-5023.dfy(157,4): Error: field 'five', which is subject to definite-assignment rules, might be uninitialized at this point in the constructor body | ||
git-issue-5023.dfy(167,11): Error: variable 'five', which is subject to definite-assignment rules, might be uninitialized here | ||
git-issue-5023.dfy(170,23): Error: variable 'five', which is subject to definite-assignment rules, might be uninitialized here | ||
|
||
Dafny program verifier finished with 7 verified, 9 errors |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Don't consider `:= *` to be a definite assignment for non-ghost variables of a `(00)` type |