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
|
// This test case is for issue 44: https://github.com/kelloggm/checker-framework/issues/44
import org.checkerframework.checker.index.qual.*;
class ArrayCreationChecks {
void test1(@Positive int x, @Positive int y) {
int[] newArray = new int[x + y];
@IndexFor("newArray") int i = x;
@IndexFor("newArray") int j = y;
}
void test2(@NonNegative int x, @Positive int y) {
int[] newArray = new int[x + y];
@IndexFor("newArray") int i = x;
@IndexOrHigh("newArray") int j = y;
}
void test3(@NonNegative int x, @NonNegative int y) {
int[] newArray = new int[x + y];
@IndexOrHigh("newArray") int i = x;
@IndexOrHigh("newArray") int j = y;
}
void test4(@GTENegativeOne int x, @NonNegative int y) {
// :: error: (array.length.negative)
int[] newArray = new int[x + y];
@LTEqLengthOf("newArray") int i = x;
// :: error: (assignment.type.incompatible)
@IndexOrHigh("newArray") int j = y;
}
void test5(@GTENegativeOne int x, @GTENegativeOne int y) {
// :: error: (array.length.negative)
int[] newArray = new int[x + y];
// :: error: (assignment.type.incompatible)
@IndexOrHigh("newArray") int i = x;
// :: error: (assignment.type.incompatible)
@IndexOrHigh("newArray") int j = y;
}
void test6(int x, int y) {
// :: error: (array.length.negative)
int[] newArray = new int[x + y];
// :: error: (assignment.type.incompatible)
@IndexFor("newArray") int i = x;
// :: error: (assignment.type.incompatible)
@IndexOrHigh("newArray") int j = y;
}
}
|