| 1 |
import testlib.wholeprograminference.qual.*; |
| 2 |
|
| 3 |
public class LUBAssignmentTest { |
| 4 |
// The default type for fields is @DefaultType. |
| 5 |
private static int privateField; |
| 6 |
public static int publicField; |
| 7 |
|
| 8 |
void assignFieldsToSibling1() { |
| 9 |
privateField = getSibling1(); |
| 10 |
publicField = getSibling1(); |
| 11 |
} |
| 12 |
|
| 13 |
static { |
| 14 |
privateField = getSibling2(); |
| 15 |
publicField = getSibling2(); |
| 16 |
} |
| 17 |
|
| 18 |
// LUB between @Sibling1 and @Sibling2 is @Parent, therefore the assignments |
| 19 |
// above refine the type of privateField to @Parent. |
| 20 |
void testFields() { |
| 21 |
// :: error: (argument.type.incompatible) |
| 22 |
expectsParent(privateField); |
| 23 |
// :: error: (argument.type.incompatible) |
| 24 |
expectsParent(publicField); |
| 25 |
} |
| 26 |
|
| 27 |
void expectsParent(@Parent int t) {} |
| 28 |
|
| 29 |
static @Sibling1 int getSibling1() { |
| 30 |
return 0; |
| 31 |
} |
| 32 |
|
| 33 |
static @Sibling2 int getSibling2() { |
| 34 |
return 0; |
| 35 |
} |
| 36 |
|
| 37 |
String lubTest2() { |
| 38 |
if (Math.random() > 0.5) { |
| 39 |
// :: warning: (cast.unsafe) |
| 40 |
@Sibling1 String s = (@Sibling1 String) ""; |
| 41 |
return s; |
| 42 |
} else { |
| 43 |
// :: warning: (cast.unsafe) |
| 44 |
@Sibling2 String s = (@Sibling2 String) ""; |
| 45 |
return s; |
| 46 |
} |
| 47 |
} |
| 48 |
} |