Repository navigation
Expand file tree
/
Copy pathErrorLoopInvariants.java
More file actions
85 lines (74 loc) · 2.05 KB
/
Copy pathErrorLoopInvariants.java
File metadata and controls
85 lines (74 loc) · 2.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package testSuite;
import liquidjava.specification.Refinement;
// Only facts that hold before a loop and are kept by every iteration are inferred for its int locals (#537)
@SuppressWarnings("unused")
public class ErrorLoopInvariants {
static boolean next() {
return true;
}
static void use(@Refinement("_ >= 0") int x) {}
static void atMostTen(@Refinement("_ <= 10") int x) {}
static void decrementing() {
for (int i = 10; i > -5; i--) {
use(i); // Expect: Refinement Error
}
}
static void resetInBody() {
int i = 0;
while (i < 10) {
use(i); // Expect: Refinement Error
i = i + 1;
if (next())
i = -1;
}
}
static void decreasedOnSomePath() {
int i = 0;
while (i < 10) {
use(i); // Expect: Refinement Error
if (next())
i = i - 2;
else
i++;
}
}
// i < 10 does not give i <= 10 at the next iteration, as i grows by 3
static void boundNotKept() {
int i = 0;
while (i < 10) {
i = i + 3;
atMostTen(i); // Expect: Refinement Error
}
}
static void decreasedBeforeContinue() {
int i = 0;
while (i < 10) {
use(i); // Expect: Refinement Error
if (next()) {
i = i - 1;
continue;
}
i++;
}
}
// the continue skips the use but not the update, which starts the next iteration from i - 5 + 1
static void decreasedBeforeContinueInFor() {
for (int i = 0; i < 10; i++) {
if (next()) {
i = i - 5;
continue;
}
use(i); // Expect: Refinement Error
}
}
static void decreasedInInnerLoop() {
int i = 0;
while (i < 10) {
use(i); // Expect: Refinement Error
for (int j = 0; j < 5; j++) {
i = i - 1;
}
i++;
}
}
}