File: Issue520.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 (43 lines) | stat: -rw-r--r-- 1,161 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
// @skip-test

// Test case for issue #520: https://github.com/typetools/checker-framework/issues/520

// compile with: $CHECKERFRAMEWORK/checker/bin-devel/javac -g Issue520.java -processor nullness
// -AprintAllQualifiers

import java.util.ArrayList;
import java.util.List;
import org.checkerframework.checker.nullness.qual.*;

public class Issue520 {}

abstract class Parent<T> {
    protected final List<? super @KeyForBottom T> list;

    public Parent(List<? super @KeyForBottom T> list) {
        this.list = list;
    }
}

abstract class Child extends Parent<CharSequence> {
    public Child(List<? super CharSequence> list) {
        super(list);
    }

    public void add(CharSequence seq) {
        list.add(seq);
    }
}

class WildCardAdd {
    List<@UnknownKeyFor ? super @KeyForBottom CharSequence> wildCardList =
            new ArrayList<@KeyForBottom CharSequence>();

    void foo(
            List<@KeyFor("m") CharSequence> keyForMCharSeq,
            @UnknownKeyFor CharSequence unknownCharSeq) {
        wildCardList = keyForMCharSeq;
        wildCardList.add(unknownCharSeq);
        @KeyFor("y") Object o = wildCardList.get(0);
    }
}