Skip to content

Commit cfc266a

Browse files
Add the list index loop from #479 as a test
Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent a0aee6f commit cfc266a

2 files changed

Lines changed: 36 additions & 0 deletions

File tree

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package testSuite.classes.loop_list_index_correct;
2+
3+
import liquidjava.specification.ExternalRefinementsFor;
4+
import liquidjava.specification.Ghost;
5+
import liquidjava.specification.Refinement;
6+
import liquidjava.specification.StateRefinement;
7+
8+
@ExternalRefinementsFor("java.util.ArrayList")
9+
@Ghost("int size")
10+
public interface ArrayListRefinements<E> {
11+
@StateRefinement(to = "size(this) == 0")
12+
void ArrayList();
13+
14+
@StateRefinement(to = "size(this) == size(old(this)) + 1")
15+
boolean add(E e);
16+
17+
E get(@Refinement("_ >= 0 && _ < size(this)") int index);
18+
19+
@Refinement("_ == size(this) && _ >= 0")
20+
int size();
21+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package testSuite.classes.loop_list_index_correct;
2+
3+
import java.util.ArrayList;
4+
5+
// A loop over the indices of a list knows the index is non-negative (#479)
6+
public class Client {
7+
public static void main(String[] args) {
8+
ArrayList<String> l = new ArrayList<>();
9+
l.add("a");
10+
l.add("b");
11+
for (int i = 0; i < l.size(); i++) {
12+
String s = l.get(i);
13+
}
14+
}
15+
}

0 commit comments

Comments
 (0)