-
Notifications
You must be signed in to change notification settings - Fork 256
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix: Optional pre-type won't cause a crash anymore (#5442)
This PR fixes #5369 I added the corresponding test. <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> --------- Co-authored-by: Remy Willems <[email protected]>
- Loading branch information
1 parent
9a7f992
commit cfc7760
Showing
8 changed files
with
58 additions
and
6 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
43 changes: 43 additions & 0 deletions
43
Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-5369.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,43 @@ | ||
// RUN: %exits-with 2 %baredafny verify %args --type-system-refresh "%s" > "%t" | ||
// RUN: %diff "%s.expect" "%t" | ||
|
||
ghost function f2(items: set<nat>): (r:nat) | ||
requires |items| > 0 { | ||
var item :| item in items; | ||
item | ||
} | ||
|
||
function f(items: set<nat>) : (r:nat) | ||
requires |items| > 0 { | ||
//assume exists item :: item in items && forall other <- items :: item == other || item < other; | ||
//assert exists item Smallest() | ||
var item :| IsSmallest(items, item); | ||
item | ||
} | ||
|
||
predicate IsSmallest(s: set<nat>, item: nat) | ||
requires item in s { | ||
m in s && forall y: nat :: y in s ==> m <= y | ||
} | ||
|
||
lemma Smallest(s: set<nat>) returns (m: nat) | ||
requires s != {} | ||
ensures m in s && IsSmallest(s, m) | ||
decreases s | ||
{ | ||
m :| m in s; | ||
if y: nat :| y in s && y < m { | ||
ghost var s' := s - {m}; | ||
assert y in s'; | ||
m := ThereIsASmallest(s'); | ||
} | ||
} | ||
|
||
function smallest(items: set<nat>): (r: nat) | ||
requires |items| > 0 | ||
|
||
method m(items: set<nat>) returns (r:nat) | ||
requires |items| > 0 { | ||
var item :| item in items; | ||
return item; | ||
} |
4 changes: 4 additions & 0 deletions
4
Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-5369.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,4 @@ | ||
git-issue-5369.dfy(20,2): Error: expression is not allowed to invoke a method (m) | ||
git-issue-5369.dfy(20,40): Error: expression is not allowed to invoke a method (m) | ||
git-issue-5369.dfy(32,9): Error: unresolved identifier: ThereIsASmallest | ||
3 resolution/type errors detected in git-issue-5369.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 @@ | ||
Optional pre-type won't cause a crash anymore |