File: LUBAssignmentTest.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 (48 lines) | stat: -rw-r--r-- 1,265 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
import testlib.wholeprograminference.qual.*;

public class LUBAssignmentTest {
    // The default type for fields is @DefaultType.
    private static int privateField;
    public static int publicField;

    void assignFieldsToSibling1() {
        privateField = getSibling1();
        publicField = getSibling1();
    }

    static {
        privateField = getSibling2();
        publicField = getSibling2();
    }

    // LUB between @Sibling1 and @Sibling2 is @Parent, therefore the assignments
    // above refine the type of privateField to @Parent.
    void testFields() {
        // :: error: (argument.type.incompatible)
        expectsParent(privateField);
        // :: error: (argument.type.incompatible)
        expectsParent(publicField);
    }

    void expectsParent(@Parent int t) {}

    static @Sibling1 int getSibling1() {
        return 0;
    }

    static @Sibling2 int getSibling2() {
        return 0;
    }

    String lubTest2() {
        if (Math.random() > 0.5) {
            // :: warning: (cast.unsafe)
            @Sibling1 String s = (@Sibling1 String) "";
            return s;
        } else {
            // :: warning: (cast.unsafe)
            @Sibling2 String s = (@Sibling2 String) "";
            return s;
        }
    }
}