summaryrefslogtreecommitdiff
path: root/Test
diff options
context:
space:
mode:
authorGravatar Rustan Leino <leino@microsoft.com>2012-07-03 01:13:44 -0700
committerGravatar Rustan Leino <leino@microsoft.com>2012-07-03 01:13:44 -0700
commitf5b08b01bd06a4ce88f6cc28f30eb180b45d1419 (patch)
treecae4418a6b07e0e8587e49929a86e560793aa11f /Test
parentc66dc1ecd384fdcd402a65ac86824327ee32eb1e (diff)
Dafny: added copredicates
Diffstat (limited to 'Test')
-rw-r--r--Test/dafny0/Answer6
-rw-r--r--Test/dafny0/Coinductive.dfy41
2 files changed, 46 insertions, 1 deletions
diff --git a/Test/dafny0/Answer b/Test/dafny0/Answer
index 85958099..7879483d 100644
--- a/Test/dafny0/Answer
+++ b/Test/dafny0/Answer
@@ -1273,7 +1273,11 @@ Coinductive.dfy(10,11): Error: because of cyclic dependencies among constructor
Coinductive.dfy(13,11): Error: because of cyclic dependencies among constructor argument types, no instances of datatype 'D' can be constructed
Coinductive.dfy(35,11): Error: because of cyclic dependencies among constructor argument types, no instances of datatype 'K' can be constructed
Coinductive.dfy(61,11): Error: because of cyclic dependencies among constructor argument types, no instances of datatype 'NotFiniteEnough_Dt' can be constructed
-4 resolution/type errors detected in Coinductive.dfy
+Coinductive.dfy(90,8): Error: a recursive copredicate call can only be done in positive positions
+Coinductive.dfy(91,8): Error: a recursive copredicate call can only be done in positive positions
+Coinductive.dfy(92,8): Error: a recursive copredicate call can only be done in positive positions
+Coinductive.dfy(92,21): Error: a recursive copredicate call can only be done in positive positions
+8 resolution/type errors detected in Coinductive.dfy
-------------------- Corecursion.dfy --------------------
Corecursion.dfy(15,13): Error: failure to decrease termination measure (note that only functions without side effects can called co-recursively)
diff --git a/Test/dafny0/Coinductive.dfy b/Test/dafny0/Coinductive.dfy
index 35f17c1c..431d6bb1 100644
--- a/Test/dafny0/Coinductive.dfy
+++ b/Test/dafny0/Coinductive.dfy
@@ -62,4 +62,45 @@ module TestCoinductiveDatatypes
}
+// --------------- CoPredicates --------------------------
+
+module CoPredicateResolutionErrors {
+
+ codatatype Stream<T> = StreamCons(head: T, tail: Stream);
+
+ function Upward(n: int): Stream<int>
+ {
+ StreamCons(n, Upward(n + 1))
+ }
+
+ function Doubles(n: int): Stream<int>
+ {
+ StreamCons(2*n, Doubles(n + 1))
+ }
+
+ copredicate Pos(s: Stream<int>)
+ {
+ 0 < s.head && Pos(s.tail) && Even(s)
+ }
+
+ copredicate Even(s: Stream<int>)
+ {
+ s.head % 2 == 0 && Even(s.tail)
+ && (s.head == 17 ==> Pos(s))
+ && (Pos(s) ==> s.head == 17) // error: cannot make recursive copredicate call in negative position
+ && !Even(s) // error: cannot make recursive copredicate call in negative position
+ && (Even(s) <==> Even(s)) // error (x2): recursive copredicate calls allowed only in positive positions
+ }
+
+ copredicate Another(s: Stream<int>)
+ {
+ !Even(s) // here, negation is fine
+ }
+
+ ghost method Lemma(n: int)
+ ensures Even(Doubles(n));
+ {
+ }
+}
+
// --------------------------------------------------