Skip to content

Commit 8abfebb

Browse files
committed
Preserve State in State Refinements without Postcondition
1 parent f8d3f3e commit 8abfebb

File tree

4 files changed

+39
-6
lines changed

4 files changed

+39
-6
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package testSuite.classes.state_refinement_no_to_correct;
2+
3+
import liquidjava.specification.ExternalRefinementsFor;
4+
import liquidjava.specification.RefinementPredicate;
5+
import liquidjava.specification.StateRefinement;
6+
7+
@ExternalRefinementsFor("java.util.ArrayList")
8+
public interface ArrayListRefinements<E> {
9+
10+
@RefinementPredicate("int size(ArrayList l)")
11+
@StateRefinement(to = "size(this) == 0")
12+
public void ArrayList();
13+
14+
@StateRefinement(to = "size(this) == size(old(this)) + 1")
15+
public boolean add(E e);
16+
17+
@StateRefinement(from = "size(this) > 0")
18+
public E get(int index);
19+
20+
@StateRefinement(from = "size(this) == 2", to = "size(this) == size(old(this)) - 1")
21+
public E remove(int index);
22+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package testSuite.classes.state_refinement_no_to_correct;
2+
3+
import java.util.ArrayList;
4+
5+
public class Test {
6+
public void example() {
7+
ArrayList<Integer> list = new ArrayList<>();
8+
list.add(1);
9+
list.add(2);
10+
list.get(0);
11+
list.remove(0);
12+
}
13+
}

liquidjava-verifier/src/main/java/liquidjava/processor/context/ObjectState.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,9 @@ public void setMessage(String message) {
5555
}
5656

5757
public ObjectState clone() {
58-
return new ObjectState(from.clone(), to.clone(), message);
58+
Predicate clonedFrom = from == null ? null : from.clone();
59+
Predicate clonedTo = to == null ? null : to.clone();
60+
return new ObjectState(clonedFrom, clonedTo, message);
5961
}
6062

6163
@Override

liquidjava-verifier/src/main/java/liquidjava/processor/refinement_checker/object_checkers/AuxStateHandler.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -182,10 +182,6 @@ private static ObjectState getStates(CtAnnotation<? extends Annotation> ctAnnota
182182
if (to != null)
183183
state.setTo(createStatePredicate(to, f.getTargetClass(), tc, e, true, prefix));
184184

185-
// has from but not to, state remains the same
186-
if (from != null && to == null)
187-
state.setTo(createStatePredicate(from, f.getTargetClass(), tc, e, true, prefix));
188-
189185
// has to but not from, state enters with true
190186
if (from == null && to != null)
191187
state.setFrom(new Predicate());
@@ -616,4 +612,4 @@ private static List<CtAnnotation<? extends Annotation>> getStateAnnotation(CtEle
616612
.getCanonicalName().contentEquals("liquidjava.specification.StateRefinement"))
617613
.collect(Collectors.toList());
618614
}
619-
}
615+
}

0 commit comments

Comments
 (0)