File: ValueWrapperCast.java

package info (click to toggle)
checker-framework-java 3.2.0%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 22,840 kB
  • sloc: java: 145,910; xml: 839; sh: 518; makefile: 401; perl: 26
file content (59 lines) | stat: -rw-r--r-- 2,333 bytes parent folder | download | duplicates (3)
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
// Test case for issue 2815: https://github.com/typetools/checker-framework/issues/2815

import org.checkerframework.common.value.qual.*;

class ValueWrapperCast {
    void testShort_plus(@IntRange(from = 0) Short x) {
        @IntRange(from = 1, to = Short.MAX_VALUE + 1) int y = x + 1;
        // :: error: (assignment.type.incompatible)
        @IntRange(from = 1, to = Short.MAX_VALUE - 1) int z = x;
    }

    void testIntFrom(@IntRange(from = 0) Integer x) {
        @IntRange(from = 0, to = Integer.MAX_VALUE) long y = x;
        // :: error: (assignment.type.incompatible)
        @IntRange(from = 0, to = Integer.MAX_VALUE - 1) int z = x;
    }

    void testShortFrom(@IntRange(from = 0) Short x) {
        @IntRange(from = 0, to = Short.MAX_VALUE) int y = x;
        // :: error: (assignment.type.incompatible)
        @IntRange(from = 0, to = Short.MAX_VALUE - 1) int z = x;
    }

    void testCharFrom(@IntRange(from = 0) Character x) {
        @IntRange(from = 0, to = Character.MAX_VALUE) int y = x;
        // :: error: (assignment.type.incompatible)
        @IntRange(from = 0, to = Character.MAX_VALUE - 1) int z = x;
    }

    void testByteFrom(@IntRange(from = 0) Byte x) {
        @IntRange(from = 0, to = Byte.MAX_VALUE) int y = x;
        // :: error: (assignment.type.incompatible)
        @IntRange(from = 0, to = Byte.MAX_VALUE - 1) int z = x;
    }

    void testIntTo(@IntRange(to = 0) Integer x) {
        @IntRange(to = 0, from = Integer.MIN_VALUE) long y = x;
        // :: error: (assignment.type.incompatible)
        @IntRange(to = 0, from = Integer.MIN_VALUE + 1) int z = x;
    }

    void testShortTo(@IntRange(to = 0) Short x) {
        @IntRange(to = 0, from = Short.MIN_VALUE) int y = x;
        // :: error: (assignment.type.incompatible)
        @IntRange(to = 0, from = Short.MIN_VALUE + 1) int z = x;
    }

    void testCharTo(@IntRange(to = 1) Character x) {
        @IntRange(to = 1, from = Character.MIN_VALUE) int y = x;
        // :: error: (assignment.type.incompatible)
        @IntRange(to = 1, from = Character.MIN_VALUE + 1) int z = x;
    }

    void testByteTo(@IntRange(to = 0) Byte x) {
        @IntRange(to = 0, from = Byte.MIN_VALUE) int y = x;
        // :: error: (assignment.type.incompatible)
        @IntRange(to = 0, from = Byte.MIN_VALUE + 1) int z = x;
    }
}