| 1 |
import org.checkerframework.common.value.qual.*; |
| 2 |
|
| 3 |
public class TransferSub { |
| 4 |
|
| 5 |
void test() { |
| 6 |
// zero, one, and two |
| 7 |
int a = 1; |
| 8 |
|
| 9 |
@IntRange(from = 0) int b = a - 1; |
| 10 |
// :: error: (assignment.type.incompatible) |
| 11 |
@IntRange(from = 1) int c = a - 1; |
| 12 |
@IntRange(from = -1) int d = a - 2; |
| 13 |
|
| 14 |
// :: error: (assignment.type.incompatible) |
| 15 |
@IntRange(from = 0) int e = a - 2; |
| 16 |
|
| 17 |
@IntRange(from = -1) int f = b - 1; |
| 18 |
// :: error: (assignment.type.incompatible) |
| 19 |
@IntRange(from = 0) int g = b - 1; |
| 20 |
|
| 21 |
// :: error: (assignment.type.incompatible) |
| 22 |
@IntRange(from = -1) int h = f - 1; |
| 23 |
|
| 24 |
@IntRange(from = -1) int i = f - 0; |
| 25 |
@IntRange(from = 0) int j = b - 0; |
| 26 |
@IntRange(from = 1) int k = a - 0; |
| 27 |
|
| 28 |
// :: error: (assignment.type.incompatible) |
| 29 |
@IntRange(from = 1) int l = j - 0; |
| 30 |
// :: error: (assignment.type.incompatible) |
| 31 |
@IntRange(from = 0) int m = i - 0; |
| 32 |
|
| 33 |
// :: error: (assignment.type.incompatible) |
| 34 |
@IntRange(from = 1) int n = a - k; |
| 35 |
// this would be an error if the values of b and j (both zero) weren't known at compile time |
| 36 |
@IntRange(from = 0) int o = b - j; |
| 37 |
/* i and d both have compile time value -1, so this is legal. |
| 38 |
The general case of GTEN1 - GTEN1 is not, though. */ |
| 39 |
@IntRange(from = -1) int p = i - d; |
| 40 |
|
| 41 |
// decrements |
| 42 |
|
| 43 |
// :: error: (unary.decrement.type.incompatible) |
| 44 |
// :: error: (assignment.type.incompatible) |
| 45 |
@IntRange(from = 1) int q = --k; // k = 0 |
| 46 |
|
| 47 |
// :: error: (unary.decrement.type.incompatible) |
| 48 |
@IntRange(from = 0) int r = k--; // after this k = -1 |
| 49 |
|
| 50 |
int k1 = 0; |
| 51 |
@IntRange(from = 0) int s = k1--; |
| 52 |
|
| 53 |
// :: error: (assignment.type.incompatible) |
| 54 |
@IntRange(from = 0) int s1 = k1; |
| 55 |
|
| 56 |
k1 = 1; |
| 57 |
@IntRange(from = 0) int t = --k1; |
| 58 |
|
| 59 |
k1 = 1; |
| 60 |
// :: error: (assignment.type.incompatible) |
| 61 |
@IntRange(from = 1) int t1 = --k1; |
| 62 |
|
| 63 |
int u1 = -1; |
| 64 |
@IntRange(from = -1) int x = u1--; |
| 65 |
// :: error: (assignment.type.incompatible) |
| 66 |
@IntRange(from = -1) int x1 = u1; |
| 67 |
} |
| 68 |
} |