File: TestInstance.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 (44 lines) | stat: -rw-r--r-- 1,369 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
import org.checkerframework.checker.fenum.qual.Fenum;

@SuppressWarnings("fenum:assignment.type.incompatible")
public class TestInstance {
    public final @Fenum("A") Object ACONST1 = new Object();
    public final @Fenum("A") Object ACONST2 = new Object();
    public final @Fenum("A") Object ACONST3 = new Object();

    public final @Fenum("B") Object BCONST1 = new Object();
    public final @Fenum("B") Object BCONST2 = new Object();
    public final @Fenum("B") Object BCONST3 = new Object();
}

class FenumUserTestInstance {
    @Fenum("A") Object state1 = new TestInstance().ACONST1;

    // :: error: (assignment.type.incompatible)
    @Fenum("B") Object state2 = new TestInstance().ACONST1;

    void foo(TestInstance t) {
        // :: error: (assignment.type.incompatible)
        state1 = new Object();

        state1 = t.ACONST2;
        state1 = t.ACONST3;

        // :: error: (assignment.type.incompatible)
        state1 = t.BCONST1;

        // :: error: (method.invocation.invalid)
        state1.hashCode();
        // :: error: (method.invocation.invalid)
        t.ACONST1.hashCode();

        // sanity check: unqualified instantiation and call work.
        Object o = new Object();
        o.hashCode();

        if (t.ACONST1 == t.ACONST2) {}

        // :: error: (binary.type.incompatible)
        if (t.ACONST1 == t.BCONST2) {}
    }
}