summaryrefslogtreecommitdiff
path: root/Test/hofs/Classes.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/hofs/Classes.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/hofs/Classes.dfy')
-rw-r--r--Test/hofs/Classes.dfy50
1 files changed, 50 insertions, 0 deletions
diff --git a/Test/hofs/Classes.dfy b/Test/hofs/Classes.dfy
new file mode 100644
index 00000000..91d7e384
--- /dev/null
+++ b/Test/hofs/Classes.dfy
@@ -0,0 +1,50 @@
+// RUN: %dafny /compile:0 "%s" > "%t"
+// RUN: %diff "%s.expect" "%t"
+
+
+class C {
+ static function method Static() : bool
+ {
+ true
+ }
+}
+
+method K() {
+ var f := C.Static;
+ var o : object;
+ assert o !in f.reads();
+ assert f.requires();
+ assert f();
+}
+
+
+class T {
+ var h : int -> int;
+}
+
+function B(t : T) : int -> int
+ requires t != null;
+ reads t;
+{
+ t.h
+}
+
+function J(t : T) : int
+ requires t != null;
+ requires t.h.reads(0) == {};
+ reads t;
+ reads if t != null then t.h.reads(0) else {};
+{
+ if t.h.requires(0) then
+ B(t)(0)
+ else
+ B(t)(0) // fail
+}
+
+method U(t : T)
+ requires t != null;
+ modifies t;
+{
+ t.h := x => x;
+ assert J(t) == 0; // ok
+}