File: Raw3.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 (85 lines) | stat: -rw-r--r-- 2,465 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
import java.util.ArrayList;
import java.util.List;
import org.checkerframework.checker.interning.qual.*;

/*
 * TODO: Make diamond cleverer:
 *     List<@Interned String> sl = new ArrayList<>();
 * currently is interpreted as
 *     List<@Interned String> sl = new ArrayList<String>();
 * and then the assignment fails.
 */
class Raw3 {

    // We would like behavior that is as similar as possible between the
    // versions with no raw types and those with raw types.

    // no raw types
    List<String> foo1() {
        List<String> sl = new ArrayList<>();
        return (List<String>) sl;
    }

    // with raw types
    List<String> foo2() {
        List<String> sl = new ArrayList<>();
        // :: warning: [unchecked] unchecked conversion
        return (List) sl;
    }

    // no raw types
    List<String> foo3() {
        List<@Interned String> sl = new ArrayList<>();
        // :: error: (return.type.incompatible)
        return (List<@Interned String>) sl;
    }

    // with raw types
    List<String> foo4() {
        List<@Interned String> sl = new ArrayList<>();
        // :: warning: [unchecked] unchecked conversion
        return (List) sl;
    }

    // no raw types
    List<@Interned String> foo5() {
        List<String> sl = new ArrayList<>();
        // :: error: (return.type.incompatible)
        return (List<String>) sl;
    }

    // with raw types
    List<@Interned String> foo6() {
        List<String> sl = new ArrayList<>();
        // :: warning: [unchecked] unchecked conversion
        return (List) sl;
    }

    class TestList<T> {
        List<String> bar1() {
            List<String> sl = new ArrayList<>();
            return (List<String>) sl;
        }

        List<String> bar2() {
            List<String> sl = new ArrayList<>();
            // :: warning: [unchecked] unchecked conversion
            return (List) sl;
        }

        List<String> bar3(List<String> sl) {
            // :: warning: [unchecked] unchecked conversion
            return (List) sl;
        }

        class DuoList<S, T> extends ArrayList<S> {}

        List<String> bar4(List<String> sl) {
            // This line was previously failing because we couldn't adequately infer the
            // type of DuoList as a List; it works now, though the future checking of rawtypes
            // may be more strict
            // :: warning: [unchecked] unchecked conversion
            return (DuoList) sl;
        }
    }
}