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 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
|
// Test case for Issue 1218:
// https://github.com/typetools/checker-framework/issues/1218
import java.io.Serializable;
import org.checkerframework.common.value.qual.*;
class Issue1218 {
enum MyEnum {
A,
B,
C;
}
class ForString {
ForString(String @MinLen(2) ... strs) {}
}
class ForInt {
ForInt(@IntVal({1, 2, 3}) int @MinLen(2) ... strs) {}
}
class ForEnum<E extends Enum<E>> {
@SafeVarargs
ForEnum(E @MinLen(2) ... enums) {}
}
class ForAny<T> {
@SafeVarargs
ForAny(T @MinLen(3) ... anys) {}
}
void strs(String @MinLen(2) ... strs) {}
void ints(@IntVal({1, 2, 3}) int @MinLen(2) ... ints) {}
@SafeVarargs
final <E extends Enum<E>> void enums(E @MinLen(2) ... enums) {}
@SafeVarargs
final <T> void anys(T @MinLen(3) ... anys) {}
void testMethodCall() {
// :: error: (varargs.type.incompatible)
strs();
// :: error: (varargs.type.incompatible)
strs("");
strs("", "");
// type of arg should be @UnknownVal String @BottomVal []
strs((String[]) null);
String[] args0 = {""};
String[] args1 = {""};
String[] args2 = {"", ""};
// :: error: (argument.type.incompatible)
strs(args0);
// :: error: (argument.type.incompatible)
strs(args1);
strs(args2);
ints(1, 2);
// :: error: (argument.type.incompatible)
ints(0, 0, 0);
// :: error: (varargs.type.incompatible)
ints(3);
// type of arg should be @IntVal(1) int @BottomVal []
ints((@IntVal(1) int[]) null);
}
void testMethodCallTypeInferred() {
// :: error: (varargs.type.incompatible)
enums();
// :: error: (varargs.type.incompatible)
enums(MyEnum.A);
enums(MyEnum.A, MyEnum.B);
enums(MyEnum.A, MyEnum.B, MyEnum.C);
}
<T extends Comparable<T> & Serializable> void testMethodCallTypeInferredIntersection() {
T t = null;
// :: error: (varargs.type.incompatible)
anys(1, 1.0);
// :: error: (varargs.type.incompatible)
anys(1, "");
anys(1, 1.0, "");
// :: error: (varargs.type.incompatible)
anys(1, t);
anys(1, t, "");
}
void testConstructorCall() {
// :: error: (varargs.type.incompatible)
new ForString();
// :: error: (varargs.type.incompatible)
new ForString("");
new ForString("", "");
// type of arg should be @UnknownVal String @BottomVal []
new ForString((String[]) null);
String[] args0 = {""};
String[] args1 = {""};
String[] args2 = {"", ""};
// :: error: (argument.type.incompatible)
new ForString(args0);
// :: error: (argument.type.incompatible)
new ForString(args1);
new ForString(args2);
new ForInt(1, 2);
// :: error: (argument.type.incompatible)
new ForInt(0, 0, 0);
// :: error: (varargs.type.incompatible)
new ForInt(3);
// type of arg should be @IntVal(1) int @BottomVal []
ints((@IntVal(1) int[]) null);
}
void testConstructorCallTypeInferred() {
// :: error: (varargs.type.incompatible)
new ForEnum<>(MyEnum.A);
new ForEnum<>(MyEnum.A, MyEnum.B);
new ForEnum<>(MyEnum.A, MyEnum.B, MyEnum.C);
}
@SuppressWarnings("unchecked")
<T extends Comparable<T> & Serializable> void testConstructorCallTypeInferredIntersection() {
T t = null;
// :: error: (varargs.type.incompatible)
new ForAny<>(1, 1.0);
// :: error: (varargs.type.incompatible)
new ForAny<>(1, "");
new ForAny<>(1, 1.0, "");
// :: error: (varargs.type.incompatible)
new ForAny<>(1, t);
new ForAny<>(1, t, "");
}
}
|