File: InvariantTypes.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 (119 lines) | stat: -rw-r--r-- 3,770 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import org.checkerframework.checker.regex.qual.*;
import org.checkerframework.framework.type.AnnotatedTypeMirror;

public class InvariantTypes {
    String[] sa = {"a"};
    String[] sa2 = {"a", "b"};
    public String[] sa3 = {"a", "b"};
    public static String[] sa4 = {"a", "b"};
    public final String[] sa5 = {"a", "b"};
    public static final String[] sa6 = {"a", "b"};
    final String[] sa7 = {"a", "b"};

    // tested above:  String[] sa = {"a"};
    @Regex String[] rsa = {"a"};
    String[] nrsa = {"(a"};
    // :: error: (array.initializer.type.incompatible) :: error: (assignment.type.incompatible)
    @Regex String[] rsaerr = {"(a"};

    List<String> ls = Arrays.asList("alice", "bob", "carol");
    List<@Regex String> lrs = Arrays.asList("alice", "bob", "carol");
    List<String> lnrs = Arrays.asList("(alice", "bob", "carol");
    // :: error: (assignment.type.incompatible)
    List<@Regex String> lrserr = Arrays.asList("(alice", "bob", "carol");

    void unqm(String[] sa) {}

    void rem(@Regex String[] rsa) {}

    void recalls() {
        unqm(new String[] {"a"});
        // TODOINVARR:: error: (argument.type.incompatible)
        unqm(new @Regex String[] {"a"});
        rem(new String[] {"a"});
        rem(new @Regex String[] {"a"});
    }

    void unqcalls() {
        unqm(new String[] {"a("});
        // TODOINVARR:: error: (argument.type.incompatible)
        // :: error: (array.initializer.type.incompatible)
        unqm(new @Regex String[] {"a("});
        // :: error: (argument.type.incompatible)
        rem(new String[] {"a("});
        // :: error: (array.initializer.type.incompatible)
        rem(new @Regex String[] {"a("});
    }

    // method argument context

    String[] retunqm(String[] sa) {
        return sa;
    }

    @Regex String[] retrem(@Regex String[] rsa) {
        return rsa;
    }

    @Regex String[] mixedm(String[] rsa) {
        return null;
    }

    void retunqcalls() {
        @Regex String[] re = mixedm(new String[] {"a("});
        // TODOINVARR:: error: (argument.type.incompatible)
        String[] u = retunqm(new String[] {"a"});
        // TODOINVARR:: error: (argument.type.incompatible)
        re = mixedm(new String[2]);
    }

    void lrem(List<@Regex String> p) {}

    void lunqm(List<String> p) {}

    void listcalls() {
        lunqm(Arrays.asList("alice", "bob", "carol"));
        lrem(Arrays.asList("alice", "bob", "carol"));
        lunqm(Arrays.asList("(alice", "bob", "carol"));
        // :: error: (argument.type.incompatible)
        lrem(Arrays.asList("(alice", "bob", "carol"));
    }

    class ReTests {
        ReTests(List<@Regex String> p) {}

        ReTests(List<String> p, int i) {}
    }

    void listctrs() {
        new ReTests(Arrays.asList("alice", "bob", "carol"), 0);
        new ReTests(Arrays.asList("alice", "bob", "carol"));
        new ReTests(Arrays.asList("(alice", "bob", "carol"), 0);
        // :: error: (argument.type.incompatible)
        new ReTests(Arrays.asList("(alice", "bob", "carol"));
    }

    <J> String join(final String delimiter, final Collection<J> objs) {
        return delimiter;
    }

    String s1 = join(" ", Arrays.asList("1", "2", "3"));
    String s2 = "xxx" + join(" ", Arrays.asList("1", "2", "3"));

    <K extends AnnotatedTypeMirror, V extends AnnotatedTypeMirror> V mapGetHelper(
            Map<K, V> mappings) {
        return null;
    }

    Map<? extends AnnotatedTypeMirror, ? extends AnnotatedTypeMirror> mappings;
    AnnotatedTypeMirror found = mapGetHelper(mappings);

    class TV<T> {
        List<List<T>> emptylist = Collections.emptyList();
    }
}