summaryrefslogtreecommitdiff
path: root/Test/dafny0/SmallTests.dfy
diff options
context:
space:
mode:
authorGravatar rustanleino <unknown>2011-02-17 23:46:15 +0000
committerGravatar rustanleino <unknown>2011-02-17 23:46:15 +0000
commit320a0392daf9cbb9d4d2b0d0c0ee66c0392f858f (patch)
treee0beded0a34f1483851a1880f00bda98cadaea3c /Test/dafny0/SmallTests.dfy
parent94025aeed7bffe21b5be543c63dce7e9b255fce5 (diff)
Dafny:
* Big change: Add type and allocatedness information everywhere in the Boogie translation. This not only fixes some potential soundness problems (see Test/dafny1/TypeAntecedents.dfy), but it also gives more information about the program. On the downside, it also requires discharging more antecedents in order to use some axioms. Another downside is that overall performance has gone down (however, this may be just an indirect consequence of the change, as it was in one investigated case). * Increase the applicability of function axioms (extending the coarse-grain function/module height mechanism used as an antecedent of function axioms). (Internally, this uses the new canCall mechanism.) * Extend language with "allocated( Expr )" expressions, which for any type of expression "Expr" says that "Expr" is allocated and has the expected type. * More details error messages about ill-defined expressions (internally, by using CheckWellformedness instead of "assert IsTotal") * Add axioms about idempotence of set union and intersection * The compiler does not support (the experimental feature) coupling invariants, so generate error if the compiler ever gets one * In the implementation, combine common behavior of MatchCaseStmt and MatchCaseExpr into a superclass MatchCase * Fixed error in translation of while(*)
Diffstat (limited to 'Test/dafny0/SmallTests.dfy')
-rw-r--r--Test/dafny0/SmallTests.dfy54
1 files changed, 52 insertions, 2 deletions
diff --git a/Test/dafny0/SmallTests.dfy b/Test/dafny0/SmallTests.dfy
index 87bfd35f..2eca82fd 100644
--- a/Test/dafny0/SmallTests.dfy
+++ b/Test/dafny0/SmallTests.dfy
@@ -79,8 +79,8 @@ class Modifies {
{
x := x + 1;
while (p != null && p.x < 75)
- decreases 75 - p.x; // error: not defined at top of each iteration (there's good reason to
- { // insist on this; for example, the decrement check could not be performed
+ decreases 75 - p.x; // error: not defined (null deref) at top of each iteration (there's good reason
+ { // to insist on this; for example, the decrement check could not be performed
p.x := p.x + 1; // at the end of the loop body if p were set to null in the loop body)
}
}
@@ -182,3 +182,53 @@ class Modifies {
}
}
}
+
+// ------------------ allocated --------------------------------------------------
+
+class AllocatedTests {
+ method M(r: AllocatedTests, k: Node, S: set<Node>, d: Lindgren)
+ {
+ assert allocated(r);
+
+ var n := new Node;
+ var t := S + {n};
+ assert allocated(t);
+
+ assert allocated(d);
+ if (*) {
+ assert old(allocated(n)); // error: n was not allocated in the initial state
+ } else {
+ assert !old(allocated(n)); // correct
+ }
+
+ var U := {k,n};
+ if (*) {
+ assert old(allocated(U)); // error: n was not allocated initially
+ } else {
+ assert !old(allocated(U)); // correct (note, the assertion does NOT say: everything was unallocated in the initial state)
+ }
+
+ assert allocated(6);
+ assert allocated(6);
+ assert allocated(null);
+ assert allocated(#Lindgren.HerrNilsson);
+
+ match (d) {
+ case Pippi(n) => assert allocated(n);
+ case Longstocking(q, dd) => assert allocated(q); assert allocated(dd);
+ case HerrNilsson => assert old(allocated(d));
+ }
+ var ls := #Lindgren.Longstocking([], d);
+ assert allocated(ls);
+ assert old(allocated(ls));
+
+ assert old(allocated(#Lindgren.Longstocking([r], d)));
+ assert old(allocated(#Lindgren.Longstocking([n], d))); // error, because n was not allocated initially
+ }
+}
+
+datatype Lindgren {
+ Pippi(Node);
+ Longstocking(seq<object>, Lindgren);
+ HerrNilsson;
+}