Repository navigation
Expand file tree
/
Copy pathErrorLoopStateFixpoint.java
More file actions
53 lines (45 loc) · 1.78 KB
/
Copy pathErrorLoopStateFixpoint.java
File metadata and controls
53 lines (45 loc) · 1.78 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
package testSuite;
import liquidjava.specification.StateRefinement;
import liquidjava.specification.StateSet;
// The states of an object at the start of every iteration of a loop are those before the loop and those at the end of
// any iteration, computed until they stop changing
@StateSet({"first", "second", "third"})
public class ErrorLoopStateFixpoint {
@StateRefinement(to = "first(this)")
ErrorLoopStateFixpoint() {}
@StateRefinement(from = "first(this)", to = "second(this)")
@StateRefinement(from = "second(this)", to = "third(this)")
@StateRefinement(from = "third(this)")
void step() {}
@StateRefinement(from = "first(this)")
@StateRefinement(from = "second(this)")
void early() {}
@StateRefinement(from = "third(this)")
void last() {}
// third is reached in the third iteration only, after the states grow twice
static void thirdIteration(int n) {
ErrorLoopStateFixpoint o = new ErrorLoopStateFixpoint();
for (int i = 0; i < n; i++) {
o.early(); // Expect: State Refinement Error
o.step();
}
}
// after two steps in the loop, o may still be first or second
static void notEnoughIterations(int n) {
ErrorLoopStateFixpoint o = new ErrorLoopStateFixpoint();
while (n > 0) {
o.step();
o.step();
n--;
}
o.last(); // Expect: State Refinement Error
}
// the error in the lambda is reported once, although the loop body is checked from more than one set of states
static void errorInLambdaInLoop(int n) {
ErrorLoopStateFixpoint o = new ErrorLoopStateFixpoint();
for (int i = 0; i < n; i++) {
o.step();
Runnable r = () -> o.last(); // Expect: State Refinement Error
}
}
}