summaryrefslogtreecommitdiff
path: root/Test/dafny0/Newtypes.dfy
diff options
context:
space:
mode:
authorGravatar leino <unknown>2014-10-21 18:28:42 -0700
committerGravatar leino <unknown>2014-10-21 18:28:42 -0700
commit13d181a688ef5a5f1acd72928f7bef12d146ebad (patch)
treeba12e381748c1892e4e12e747fce7f65a6ad60d3 /Test/dafny0/Newtypes.dfy
parente94dc5817a729ebdd6786deb17e1903974c8b981 (diff)
When guessing decreases clauses for loops, convert numeric values to their ultimate base type (int or real) before subtracting
Diffstat (limited to 'Test/dafny0/Newtypes.dfy')
-rw-r--r--Test/dafny0/Newtypes.dfy82
1 files changed, 82 insertions, 0 deletions
diff --git a/Test/dafny0/Newtypes.dfy b/Test/dafny0/Newtypes.dfy
index bab42378..db737f68 100644
--- a/Test/dafny0/Newtypes.dfy
+++ b/Test/dafny0/Newtypes.dfy
@@ -227,3 +227,85 @@ module IntegerBasedValues {
}
}
}
+
+module Guessing_Termination_Metrics {
+ newtype N = x | x == 0 || x == 3 || x == 7
+
+ method M_Bad() {
+ var x: N, y: N;
+ while x < y
+ decreases y - x; // error: y-x may not be an N
+ {
+ if 3 < y {
+ y := 3;
+ } else {
+ x := 3;
+ }
+ }
+ }
+
+ method M_Good() {
+ var x: N, y: N;
+ while x < y
+ decreases int(y) - int(x);
+ {
+ if 3 < y {
+ y := 3;
+ } else {
+ x := 3;
+ }
+ }
+ }
+
+ method M_Inferred() {
+ var x: N, y: N;
+ while x < y // the inferred decreases clause includes the type conversion to int
+ {
+ if 3 < y {
+ y := 3;
+ } else {
+ x := 3;
+ }
+ }
+ }
+
+ newtype R = r | r == 0.0 || 10.0 <= r <= 20.0
+
+ method P_Bad() {
+ var x: R, y: R;
+ while x < y
+ decreases y - x; // error: y-x may not be an R
+ {
+ if 12.0 < y {
+ y := 10.0;
+ } else {
+ x := 14.2;
+ }
+ }
+ }
+
+ method P_Good() {
+ var x: R, y: R;
+ while x < y
+ decreases real(y) - real(x);
+ {
+ if 12.0 < y {
+ y := 10.0;
+ } else {
+ x := 14.2;
+ }
+ }
+ }
+
+ method P_Inferred() {
+ var x: R, y: R;
+ while x < y // the inferred decreases clause includes the type conversion to real
+ {
+ if 12.0 < y {
+ y := 10.0;
+ } else {
+ x := 14.2;
+ }
+ }
+ }
+}