File: CompoundAssignment.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 (67 lines) | stat: -rw-r--r-- 1,863 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
// General test cases for compound assignments
// Also test case for Issue 624
// https://github.com/typetools/checker-framework/issues/624

import org.checkerframework.common.value.qual.IntVal;
import org.checkerframework.common.value.qual.StringVal;

public class CompoundAssignment {

    @StringVal("hello") String field;

    public void refinements() {
        field = "hello";
        // :: error: (compound.assignment.type.incompatible)
        field += method();
        // :: error: (assignment.type.incompatible)
        // :: error: (compound.assignment.type.incompatible)
        @StringVal("hellohellohello") String test = field += method();
    }

    @StringVal("hello") String method() {
        // :: error: (assignment.type.incompatible)
        field = "goodbye";
        return "hello";
    }

    void value() {
        @StringVal("hello") String s = "hello";
        // :: error: (compound.assignment.type.incompatible)
        s += "hello";

        @IntVal(1) int i = 1;
        // :: error: (compound.assignment.type.incompatible)
        i += 1;

        @IntVal(2) int j = 2;
        // :: error: (compound.assignment.type.incompatible)
        j += 2;

        // :: error: (assignment.type.incompatible)
        @IntVal(4) int four = j;
    }

    void value2() {
        @StringVal("hello") String s = "hello";
        // :: error: (assignment.type.incompatible)
        s = s + "hello";

        @IntVal(1) int i = 1;
        // :: error: (assignment.type.incompatible)
        i = i + 1;
    }

    void noErrorCompoundAssignments() {
        @IntVal(0) int zero = 0;
        zero *= 12;

        @StringVal("null") String s = "null";
        s += "";
    }

    void errorCompundAssignments() {
        @StringVal("hello") String s = "hello";
        // :: error: (compound.assignment.type.incompatible)
        s += "";
    }
}