| 1 |
// General test cases for compound assignments |
| 2 |
// Also test case for Issue 624 |
| 3 |
// https://github.com/typetools/checker-framework/issues/624 |
| 4 |
|
| 5 |
import org.checkerframework.common.value.qual.IntVal; |
| 6 |
import org.checkerframework.common.value.qual.StringVal; |
| 7 |
|
| 8 |
public class CompoundAssignment { |
| 9 |
|
| 10 |
@StringVal("hello") String field; |
| 11 |
|
| 12 |
public void refinements() { |
| 13 |
field = "hello"; |
| 14 |
// :: error: (compound.assignment.type.incompatible) |
| 15 |
field += method(); |
| 16 |
// :: error: (assignment.type.incompatible) |
| 17 |
// :: error: (compound.assignment.type.incompatible) |
| 18 |
@StringVal("hellohellohello") String test = field += method(); |
| 19 |
} |
| 20 |
|
| 21 |
@StringVal("hello") String method() { |
| 22 |
// :: error: (assignment.type.incompatible) |
| 23 |
field = "goodbye"; |
| 24 |
return "hello"; |
| 25 |
} |
| 26 |
|
| 27 |
void value() { |
| 28 |
@StringVal("hello") String s = "hello"; |
| 29 |
// :: error: (compound.assignment.type.incompatible) |
| 30 |
s += "hello"; |
| 31 |
|
| 32 |
@IntVal(1) int i = 1; |
| 33 |
// :: error: (compound.assignment.type.incompatible) |
| 34 |
i += 1; |
| 35 |
|
| 36 |
@IntVal(2) int j = 2; |
| 37 |
// :: error: (compound.assignment.type.incompatible) |
| 38 |
j += 2; |
| 39 |
|
| 40 |
// :: error: (assignment.type.incompatible) |
| 41 |
@IntVal(4) int four = j; |
| 42 |
} |
| 43 |
|
| 44 |
void value2() { |
| 45 |
@StringVal("hello") String s = "hello"; |
| 46 |
// :: error: (assignment.type.incompatible) |
| 47 |
s = s + "hello"; |
| 48 |
|
| 49 |
@IntVal(1) int i = 1; |
| 50 |
// :: error: (assignment.type.incompatible) |
| 51 |
i = i + 1; |
| 52 |
} |
| 53 |
|
| 54 |
void noErrorCompoundAssignments() { |
| 55 |
@IntVal(0) int zero = 0; |
| 56 |
zero *= 12; |
| 57 |
|
| 58 |
@StringVal("null") String s = "null"; |
| 59 |
s += ""; |
| 60 |
} |
| 61 |
|
| 62 |
void errorCompundAssignments() { |
| 63 |
@StringVal("hello") String s = "hello"; |
| 64 |
s += ""; |
| 65 |
} |
| 66 |
} |