-
Notifications
You must be signed in to change notification settings - Fork 268
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix: Map range requires equality for enclosing type to support equali…
…ty (#5973) This PR fixes #5972 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>
- Loading branch information
1 parent
579df16
commit 1d74af1
Showing
4 changed files
with
90 additions
and
20 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
57 changes: 57 additions & 0 deletions
57
Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-5972.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,57 @@ | ||
// RUN: %exits-with 2 %baredafny verify %args "%s" > "%t" | ||
// RUN: %diff "%s.expect" "%t" | ||
|
||
datatype M<T, U> = M(m: map<T, U>) | ||
|
||
method CompareAnything<A>(f: A, g: A) returns (b: bool) | ||
ensures b <==> f == g | ||
{ | ||
var m1 := M(map[0 := f]); | ||
var m2 := M(map[0 := g]); | ||
assert m1 == m2 <==> f == g by { | ||
if f == g { | ||
assert m1 == m2; | ||
} | ||
if m1 == m2 { | ||
assert m1.m[0] == m2.m[0]; | ||
} | ||
} | ||
return m1 == m2; | ||
} | ||
|
||
datatype S<T> = S(s: seq<T>) | ||
|
||
method CompareAnythingS<A>(f: A, g: A) returns (b: bool) | ||
ensures b <==> f == g | ||
{ | ||
var m1 := S([f]); | ||
var m2 := S([g]); | ||
assert m1 == m2 <==> f == g by { | ||
if f == g { | ||
assert m1 == m2; | ||
} | ||
if m1 == m2 { | ||
assert m1.s[0] == m2.s[0]; | ||
} | ||
} | ||
return m1 == m2; | ||
} | ||
|
||
|
||
codatatype Stream = Stream(head: int, tail: Stream) | ||
{ | ||
static function From(i: int): Stream { | ||
Stream(i, From(i + 1)) | ||
} | ||
} | ||
|
||
method Main() { | ||
var s1 := Stream.From(0); | ||
var s2 := Stream.From(0); | ||
var b := CompareAnything(s1, s2); | ||
var b2 := CompareAnythingS(s1, s2); | ||
if !b || !b2 { | ||
assert false; | ||
print 1/0; | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-5972.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,3 @@ | ||
git-issue-5972.dfy(19,9): Error: == can only be applied to expressions of types that support equality (got M<int, A>) | ||
git-issue-5972.dfy(37,9): Error: == can only be applied to expressions of types that support equality (got S<A>) | ||
2 resolution/type errors detected in git-issue-5972.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 @@ | ||
Map range requires equality for enclosing type to support equality |