summaryrefslogtreecommitdiff
path: root/Test/dafny0/Reads.dfy
diff options
context:
space:
mode:
authorGravatar Dan Rosén <danr@chalmers.se>2014-08-11 14:57:27 -0700
committerGravatar Dan Rosén <danr@chalmers.se>2014-08-11 14:57:27 -0700
commit4cbe4583b329a39dee2b4b456758cafbe7e2fa79 (patch)
tree6bb2377f06036fd41d939d168365d4e47cc7a327 /Test/dafny0/Reads.dfy
parentc377658acba5472b6d0c1e1452ce4c4c8f1fc28e (diff)
Add higher-order-functions and some other goodies
* The reads clause now needs to be self framing. * The requires clause now needs to be framed by the reads clause. * There are one-shot lambdas, with a single arrow, but they will probably be removed. * There is a {:heapQuantifier} attribute to quantifiers, but they will probably be removed. * Add smart handling of type variables * Add < and > for datatype & type parameter
Diffstat (limited to 'Test/dafny0/Reads.dfy')
-rw-r--r--Test/dafny0/Reads.dfy57
1 files changed, 57 insertions, 0 deletions
diff --git a/Test/dafny0/Reads.dfy b/Test/dafny0/Reads.dfy
new file mode 100644
index 00000000..645494cb
--- /dev/null
+++ b/Test/dafny0/Reads.dfy
@@ -0,0 +1,57 @@
+// RUN: %dafny /compile:0 "%s" > "%t"
+// RUN: %diff "%s.expect" "%t"
+
+// Checking that the reads clause also is checked over requires
+
+class C { var u : int; }
+
+function nope1(c : C):()
+ requires c != null && c.u > 0;
+{()}
+
+function ok1(c : C):()
+ requires c != null && c.u > 0;
+ reads c;
+{()}
+
+function nope2(c : C):()
+ requires c != null && c.u > 0;
+ reads if c != null then {} else {c};
+{()}
+
+function ok2(c : C):()
+ requires c != null && c.u > 0;
+ reads if c != null then {c} else {};
+{()}
+
+function nope3(xs : seq<C>):()
+ requires |xs| > 0 && xs[0] != null && xs[0].u > 0;
+{()}
+
+function ok3(xs : seq<C>):()
+ requires |xs| > 0 && xs[0] != null && xs[0].u > 0;
+ reads xs;
+{()}
+
+function nope4(c : C, xs : set<C>):()
+ requires c != null && c !in xs ==> c.u > 0;
+ reads xs;
+{()}
+
+function ok4(c : C, xs : set<C>):()
+ requires c != null && c in xs ==> c.u > 0;
+ reads xs;
+{()}
+
+// reads over itself
+
+class R { var r : R; }
+
+function nope5(r : R):()
+ reads if r != null then {r.r} else {};
+{()}
+
+function ok5(r : R):()
+ reads if r != null then {r, r.r} else {};
+{()}
+