File: Issue867.java

package info (click to toggle)
checker-framework-java 3.2.0%2Bds-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 23,104 kB
  • sloc: java: 145,916; xml: 839; sh: 518; makefile: 404; perl: 26
file content (68 lines) | stat: -rw-r--r-- 1,638 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
60
61
62
63
64
65
66
67
68
// Test case for Issue 867:
// https://github.com/typetools/checker-framework/issues/867

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

class Issue867 {
    void test1() {
        @IntVal({0, 1}) int x = 0;
        @IntVal(0) int zero = x++;
        @IntVal(1) int one = x;
        // :: error: (unary.increment.type.incompatible)
        x++;

        x = 1;
        one = x--;
        zero = x;
        // :: error: (unary.decrement.type.incompatible)
        x--;
    }

    void test2() {
        @IntVal({0, 1, 2}) int x = 0;
        @IntVal(1) int one = x++ + x++;
        @IntVal(2) int two = x;
        // :: error: (unary.increment.type.incompatible)
        x++;

        x = 2;
        @IntVal(3) int three = x-- + x--;
        @IntVal(0) int zero = x;
        // :: error: (unary.decrement.type.incompatible)
        x--;
    }

    void test3() {
        @IntVal({0, 1, 2}) int x = 0;
        @IntVal(2) int two = x++ + ++x;
        two = x;
        // :: error: (unary.increment.type.incompatible)
        x++;

        x = 2;
        two = x-- + --x;
        @IntVal(0) int zero = x;
        // :: error: (unary.decrement.type.incompatible)
        x--;
    }

    void test4() {
        @IntVal({0, 1}) int x = 0;
        m0(x++);
        // :: error: (argument.type.incompatible)
        m0(x);
        // :: error: (unary.increment.type.incompatible)
        m1(x++);

        x = 1;
        m1(x--);
        // :: error: (argument.type.incompatible)
        m1(x);
        // :: error: (unary.decrement.type.incompatible)
        m0(x--);
    }

    void m0(@IntVal(0) int x) {}

    void m1(@IntVal(1) int x) {}
}