summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar qunyanm <unknown>2015-04-14 10:09:03 -0700
committerGravatar qunyanm <unknown>2015-04-14 10:09:03 -0700
commit38134c5587ea53e71290e2e8ea9915062172865b (patch)
tree26116aeedd7ba60a3a3bc91d798d7ea333637d79
parent90c68ad369e3f9318d4f31ed4f9e628cb7f2738d (diff)
Fix issue #68. Change GetHashCode implementation for Sequence.
-rw-r--r--Binaries/DafnyRuntime.cs8
-rw-r--r--Test/dafny4/Bug68.dfy9
-rw-r--r--Test/dafny4/Bug68.dfy.expect6
3 files changed, 22 insertions, 1 deletions
diff --git a/Binaries/DafnyRuntime.cs b/Binaries/DafnyRuntime.cs
index ef6da67e..a682422a 100644
--- a/Binaries/DafnyRuntime.cs
+++ b/Binaries/DafnyRuntime.cs
@@ -499,7 +499,13 @@ namespace Dafny
return other is Sequence<T> && Equals((Sequence<T>)other);
}
public override int GetHashCode() {
- return elmts.GetHashCode();
+ if (elmts == null || elmts.Length == 0)
+ return 0;
+ var hashCode = 0;
+ for (var i = 0; i < elmts.Length; i++) {
+ hashCode = (hashCode << 3) | (hashCode >> 29) ^ elmts[i].GetHashCode();
+ }
+ return hashCode;
}
public override string ToString() {
if (elmts is char[]) {
diff --git a/Test/dafny4/Bug68.dfy b/Test/dafny4/Bug68.dfy
new file mode 100644
index 00000000..2736246d
--- /dev/null
+++ b/Test/dafny4/Bug68.dfy
@@ -0,0 +1,9 @@
+// RUN: %dafny /compile:3 "%s" > "%t"
+// RUN: %diff "%s.expect" "%t"
+
+method Main()
+{
+ var m := map [[10, 20] := 33];
+ assert [10, 20] in m; // succeeds
+ print [10, 20] in m; // prints False
+} \ No newline at end of file
diff --git a/Test/dafny4/Bug68.dfy.expect b/Test/dafny4/Bug68.dfy.expect
new file mode 100644
index 00000000..4fcef38e
--- /dev/null
+++ b/Test/dafny4/Bug68.dfy.expect
@@ -0,0 +1,6 @@
+
+Dafny program verifier finished with 2 verified, 0 errors
+Program compiled successfully
+Running...
+
+True \ No newline at end of file