File: IncompatibleBounds.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 (59 lines) | stat: -rw-r--r-- 2,209 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
package testchecker;

import org.checkerframework.framework.qual.DefaultQualifier;
import org.checkerframework.framework.qual.TypeUseLocation;
import testchecker.quals.*;

/**
 * This test is solely to ensure that if bounds in type parameters and wildcards are invalid then
 * they are reported as such using a "bound.type.incompatible" error.
 *
 * <p>A valid bound is one with LOWER_BOUND annotations that subtypes of UPPER_BOUND annotations.
 */

// set the defaults in the H2 hierarchy such that do not report errors in this test
@DefaultQualifier(
        value = H2Top.class,
        locations = {TypeUseLocation.UPPER_BOUND})
@DefaultQualifier(
        value = H2Bot.class,
        locations = {TypeUseLocation.LOWER_BOUND})
public class IncompatibleBounds {

    // The bounds below are valid
    class TopToBottom<@H1Bot T extends @H1Top Object> {}

    class TopToH1S1<@H1S1 TT extends @H1Top Object> {}

    class H1S1ToBot<@H1Bot TTT extends @H1S1 Object> {}

    class H1S1ToH1S1<@H1S1 TTTT extends @H1S1 Object> {}

    class ValidContext {
        TopToBottom<@H1Bot ? extends @H1Top Object> topToBot;
        TopToH1S1<@H1S1 ? extends @H1Top Object> topToH1S1;
        H1S1ToBot<@H1Bot ? extends @H1S1 Object> h1S1ToBot;
        H1S1ToH1S1<@H1S1 ? extends @H1S1 Object> h1S1ToH1S1;
    }

    // invalid combinations
    // :: error: (bound.type.incompatible)
    class BottomToTop<@H1Top U extends @H1Bot Object> {}
    // :: error: (bound.type.incompatible)
    class H1S1ToTop<@H1Top UU extends @H1S1 Object> {}
    // :: error: (bound.type.incompatible)
    class BottomToH1S1<@H1S1 UUU extends @H1Bot Object> {}
    // :: error: (bound.type.incompatible)
    class H1S2ToH1S1<@H1S1 UUUU extends @H1S2 Object> {}

    class InvalidContext {
        // :: error: (bound.type.incompatible)
        BottomToTop<@H1Top ? extends @H1Bot Object> bottomToTop;
        // :: error: (bound.type.incompatible)
        H1S1ToTop<@H1Top ? extends @H1S1 Object> h1S1ToTop;
        // :: error: (bound.type.incompatible)
        BottomToH1S1<@H1S1 ? extends @H1Bot Object> bottomToH1S1;
        // :: error: (bound.type.incompatible)
        H1S2ToH1S1<@H1S1 ? extends @H1S2 Object> h1S2ToH1S1;
    }
}