| 1 |
// Test case for issue #574: https://github.com/typetools/checker-framework/issues/574 |
| 2 |
|
| 3 |
import org.checkerframework.checker.initialization.qual.UnderInitialization; |
| 4 |
|
| 5 |
@SuppressWarnings({ |
| 6 |
// A warning is issued that fields are not initialized in the constructor. |
| 7 |
// That is expected and it is not what is being verified in this test. |
| 8 |
"initialization.fields.uninitialized", |
| 9 |
// Normally @UnknownInitialization is the only initialization annotation allowed on fields. |
| 10 |
// However, for the purposes of this test, fields must be annotated with @UnderInitialization. |
| 11 |
"initialization.invalid.field.type" |
| 12 |
}) |
| 13 |
class Issue574 { |
| 14 |
@UnderInitialization(Object.class) Object o1; |
| 15 |
|
| 16 |
@UnderInitialization(String.class) Object o2; |
| 17 |
|
| 18 |
@UnderInitialization(Character.class) Object o3; |
| 19 |
|
| 20 |
@UnderInitialization(Number.class) Object o4; |
| 21 |
|
| 22 |
@UnderInitialization(Double.class) Object o5; |
| 23 |
|
| 24 |
@UnderInitialization(Integer.class) Object o6; |
| 25 |
|
| 26 |
@UnderInitialization(CharSequence.class) Object i1; // CharSequence is an interface |
| 27 |
|
| 28 |
void testLubOfClasses(boolean flag) { |
| 29 |
@UnderInitialization(Object.class) Object l1 = flag ? o2 : o3; |
| 30 |
@UnderInitialization(Number.class) Object l2 = flag ? o5 : o6; |
| 31 |
|
| 32 |
@UnderInitialization(Object.class) Object l3 = flag ? o1 : o2; |
| 33 |
@UnderInitialization(Object.class) Object l4 = flag ? o1 : o3; |
| 34 |
|
| 35 |
@UnderInitialization(Number.class) Object l5 = flag ? o4 : o5; |
| 36 |
@UnderInitialization(Number.class) Object l6 = flag ? o4 : o6; |
| 37 |
|
| 38 |
// :: error: (assignment.type.incompatible) |
| 39 |
@UnderInitialization(Character.class) Object l7 = flag ? o1 : o2; |
| 40 |
// :: error: (assignment.type.incompatible) |
| 41 |
@UnderInitialization(Integer.class) Object l8 = flag ? o4 : o5; |
| 42 |
} |
| 43 |
|
| 44 |
void testLubOfClassesAndInterfaces(boolean flag) { |
| 45 |
@UnderInitialization(Object.class) Object l1 = flag ? i1 : o3; |
| 46 |
|
| 47 |
@UnderInitialization(Object.class) Object l2 = flag ? o1 : i1; |
| 48 |
@UnderInitialization(Object.class) Object l3 = flag ? o1 : o3; |
| 49 |
|
| 50 |
// :: error: (assignment.type.incompatible) |
| 51 |
@UnderInitialization(Character.class) Object l4 = flag ? o1 : i1; |
| 52 |
} |
| 53 |
} |