File: UpperBoundDefaulting.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 (66 lines) | stat: -rw-r--r-- 2,793 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
package defaulting.upperbound;

// This test's sole purpose is to check that implicit and explicit LOWER_BOUND defaulting work as
// expected.

import testlib.defaulting.UpperBoundQual.*;

class MyArrayList<MAL extends String> {}

class MyExplicitArray<MEA extends String> {}

public class UpperBoundDefaulting {

    public <UAL extends String> void explicitUpperBoundTypeVar() {
        MyArrayList<@UbBottom ? extends @UbBottom Object> eubBottomToBottom =
                // :: error: (assignment.type.incompatible)
                new MyArrayList<UAL>();

        MyArrayList<@UbBottom ? extends @UbExplicit Object> eubExplicitToBottom =
                new MyArrayList<UAL>();

        // :: error: (type.argument.type.incompatible)
        MyArrayList<@UbBottom ? extends @UbImplicit Object> eubImplicitToBottom =
                // :: error: (assignment.type.incompatible)
                new MyArrayList<UAL>();
    }

    public void implicitsWildcard(MyArrayList<?> myArrayList) {

        // should fail because @LbImplicit is below @UbTop
        // :: error: (type.argument.type.incompatible)
        @UbTop MyArrayList<@UbBottom ? extends @UbTop String> iwLowerBoundIncompatible = myArrayList;

        @UbTop MyArrayList<@UbBottom ? extends @UbExplicit String> iwLowerBoundCompatible = myArrayList;

        // :: error: (type.argument.type.incompatible)
        @UbTop MyArrayList<@UbBottom ? extends @UbImplicit String> iwLowerBoundStillCompatible =
                // :: error: (assignment.type.incompatible)
                myArrayList;
    }

    public void implicitExtendBoundedWildcard(MyArrayList<? extends String> iebList) {

        // should fail because @LbImplicit is below @UbTop
        // :: error: (type.argument.type.incompatible)
        @UbTop MyArrayList<@UbBottom ? extends @UbTop String> iebLowerBoundIncompatible = iebList;

        MyArrayList<@UbBottom ? extends @UbExplicit Object> eubExplicitToBottom = iebList;

        // :: error: (assignment.type.incompatible) :: error: (type.argument.type.incompatible)
        MyArrayList<@UbBottom ? extends @UbImplicit Object> eubImplicitToBottom = iebList;
    }

    public void explicitLowerBoundedWildcard(MyArrayList<? super String> elbList) {
        // should fail because @UbExplicit is below UbTop
        // :: error: (type.argument.type.incompatible)
        @UbTop MyArrayList<@UbTop ? super @UbBottom String> iebLowerBoundIncompatible = elbList;

        // :: error: (type.argument.type.incompatible)
        @UbTop MyArrayList<@UbImplicit ? super @UbBottom String> iebLowerBoundStillIncompatible =
                // :: error: (assignment.type.incompatible)
                elbList;

        @UbTop MyArrayList<@UbExplicit ? super @UbBottom String> iebLowerBoundCompatible = elbList;
    }
}