summaryrefslogtreecommitdiff
path: root/Test/dafny0
diff options
context:
space:
mode:
authorGravatar leino <unknown>2015-04-07 22:28:48 -0700
committerGravatar leino <unknown>2015-04-07 22:28:48 -0700
commita84dd34f6f784c344c25340838cee07f44df6d74 (patch)
tree836283836cb7d4ca41a04081473007c813f981ba /Test/dafny0
parent0a53dd6d6cebf42a4a685918322953ce9383a3af (diff)
Include axioms about $Is and $IsAlloc for traits
Diffstat (limited to 'Test/dafny0')
-rw-r--r--Test/dafny0/Trait/TraitExample.dfy82
-rw-r--r--Test/dafny0/Trait/TraitExample.dfy.expect7
2 files changed, 89 insertions, 0 deletions
diff --git a/Test/dafny0/Trait/TraitExample.dfy b/Test/dafny0/Trait/TraitExample.dfy
new file mode 100644
index 00000000..be38bfe5
--- /dev/null
+++ b/Test/dafny0/Trait/TraitExample.dfy
@@ -0,0 +1,82 @@
+// RUN: %dafny /compile:3 /print:"%t.print" /dprint:"%t.dprint" "%s" > "%t"
+// RUN: %diff "%s.expect" "%t"
+
+trait Automobile {
+ ghost var Repr: set<object>
+ predicate Valid()
+ reads this //, Repr
+ ensures Valid() ==> this in Repr
+ function method Brand(): string
+ var position: int
+ method Drive()
+ requires Valid()
+ modifies this // Repr
+ ensures old(position) <= position
+}
+
+class Volvo extends Automobile {
+ predicate Valid()
+ reads this //, Repr
+ ensures Valid() ==> this in Repr
+ {
+ this in Repr
+ }
+ constructor()
+ modifies this
+ ensures Valid()
+ {
+ Repr := {this};
+ }
+ function method Brand(): string {
+ "Volvo"
+ }
+ method Drive()
+// requires Valid()
+ modifies this // Repr
+ ensures old(position) <= position
+ {
+ position := position + 10;
+ }
+}
+
+class Fiat extends Automobile {
+ predicate Valid()
+ reads this // , Repr
+ ensures Valid() ==> this in Repr
+ {
+ this in Repr
+ }
+ constructor()
+ modifies this
+ ensures Valid()
+ {
+ Repr := {this};
+ }
+ function method Brand(): string {
+ "Fiat"
+ }
+ method Drive()
+// requires Valid()
+ modifies this // Repr
+ ensures old(position) <= position
+ {
+ position := position + 3;
+ }
+}
+
+method Main() {
+ var auto: Automobile;
+ auto := new Volvo();
+ WorkIt(auto);
+ auto := new Fiat();
+ WorkIt(auto);
+}
+
+method WorkIt(auto: Automobile)
+ requires auto != null && auto.Valid()
+ modifies auto // auto.Repr
+{
+ auto.Drive();
+ print auto.Brand(), ": ", auto.position, "\n";
+ auto.position := 0;
+}
diff --git a/Test/dafny0/Trait/TraitExample.dfy.expect b/Test/dafny0/Trait/TraitExample.dfy.expect
new file mode 100644
index 00000000..4fc71fb5
--- /dev/null
+++ b/Test/dafny0/Trait/TraitExample.dfy.expect
@@ -0,0 +1,7 @@
+
+Dafny program verifier finished with 25 verified, 0 errors
+Program compiled successfully
+Running...
+
+Volvo: 10
+Fiat: 3