| 1 |
// Test case for issue 557: |
| 2 |
// https://github.com/typetools/checker-framework/issues/557 |
| 3 |
|
| 4 |
import java.util.Optional; |
| 5 |
import org.checkerframework.checker.nullness.qual.Nullable; |
| 6 |
|
| 7 |
@SuppressWarnings("nullness") |
| 8 |
class MyOpt<T> { |
| 9 |
static <S> MyOpt<S> of(S p) { |
| 10 |
return null; |
| 11 |
} |
| 12 |
|
| 13 |
static <S> MyOpt<S> empty() { |
| 14 |
return null; |
| 15 |
} |
| 16 |
} |
| 17 |
|
| 18 |
@SuppressWarnings("nullness") |
| 19 |
class MyOpt2<T extends Object> { |
| 20 |
static <S extends Object> MyOpt2<S> of(S p) { |
| 21 |
return null; |
| 22 |
} |
| 23 |
|
| 24 |
static <S extends Object> MyOpt2<S> empty() { |
| 25 |
return null; |
| 26 |
} |
| 27 |
} |
| 28 |
|
| 29 |
@SuppressWarnings("nullness") |
| 30 |
class MyOpt3<T extends @Nullable Object> { |
| 31 |
static <S extends @Nullable Object> MyOpt3<S> of(S p) { |
| 32 |
return null; |
| 33 |
} |
| 34 |
|
| 35 |
static <S extends @Nullable Object> MyOpt3<S> empty() { |
| 36 |
return null; |
| 37 |
} |
| 38 |
} |
| 39 |
|
| 40 |
class Issue557a { |
| 41 |
MyOpt<String> opt(boolean flag) { |
| 42 |
return flag ? MyOpt.of("Hello") : MyOpt.empty(); |
| 43 |
} |
| 44 |
|
| 45 |
MyOpt<String> opt2() { |
| 46 |
return MyOpt.empty(); |
| 47 |
} |
| 48 |
|
| 49 |
MyOpt<String> opt3(boolean flag) { |
| 50 |
return flag ? MyOpt.of("Hello") : (flag ? MyOpt.empty() : MyOpt.empty()); |
| 51 |
} |
| 52 |
|
| 53 |
void foo(MyOpt<String> param) {} |
| 54 |
|
| 55 |
void callFoo(boolean flag) { |
| 56 |
foo(flag ? MyOpt.of("Hello") : (flag ? MyOpt.empty() : MyOpt.empty())); |
| 57 |
} |
| 58 |
} |
| 59 |
|
| 60 |
class Issue557b { |
| 61 |
MyOpt2<String> opt(boolean flag) { |
| 62 |
return flag ? MyOpt2.of("Hello") : MyOpt2.empty(); |
| 63 |
} |
| 64 |
|
| 65 |
MyOpt2<String> opt2() { |
| 66 |
return MyOpt2.empty(); |
| 67 |
} |
| 68 |
} |
| 69 |
|
| 70 |
class Issue557c { |
| 71 |
MyOpt3<String> opt(boolean flag) { |
| 72 |
return flag ? MyOpt3.of("Hello") : MyOpt3.empty(); |
| 73 |
} |
| 74 |
|
| 75 |
MyOpt3<String> opt2() { |
| 76 |
return MyOpt3.empty(); |
| 77 |
} |
| 78 |
} |
| 79 |
|
| 80 |
class Issue557d { |
| 81 |
Optional<String> opt(boolean flag) { |
| 82 |
return flag ? Optional.of("Hello") : Optional.empty(); |
| 83 |
} |
| 84 |
|
| 85 |
Optional<String> opt2() { |
| 86 |
return Optional.empty(); |
| 87 |
} |
| 88 |
} |