summaryrefslogtreecommitdiff
path: root/Test/dafny0
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
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')
-rw-r--r--Test/dafny0/Newtypes.dfy82
-rw-r--r--Test/dafny0/Newtypes.dfy.expect14
2 files changed, 95 insertions, 1 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;
+ }
+ }
+ }
+}
diff --git a/Test/dafny0/Newtypes.dfy.expect b/Test/dafny0/Newtypes.dfy.expect
index 7af53142..3ca77f1d 100644
--- a/Test/dafny0/Newtypes.dfy.expect
+++ b/Test/dafny0/Newtypes.dfy.expect
@@ -42,5 +42,17 @@ Newtypes.dfy(225,40): Error: result of operation might violate newtype constrain
Execution trace:
(0,0): anon0
(0,0): anon8_Then
+Newtypes.dfy(237,19): Error: result of operation might violate newtype constraint
+Execution trace:
+ (0,0): anon0
+ Newtypes.dfy(236,5): anon9_LoopHead
+ (0,0): anon9_LoopBody
+ (0,0): anon10_Then
+Newtypes.dfy(277,19): Error: result of operation might violate newtype constraint
+Execution trace:
+ (0,0): anon0
+ Newtypes.dfy(276,5): anon9_LoopHead
+ (0,0): anon9_LoopBody
+ (0,0): anon10_Then
-Dafny program verifier finished with 35 verified, 11 errors
+Dafny program verifier finished with 47 verified, 13 errors