Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions checker/tests/nullness/Issue8298Nullness.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Test case for https://github.com/typetools/checker-framework/issues/8298

import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;

public class Issue8298Nullness {
static class Box<T extends @Nullable Object> {}

static <T extends @Nullable Object> Box<? extends T> wildcardBox(Box<T> b) {
throw new RuntimeException();
}

static <X extends @Nullable Object> X takeExtends(Box<? extends X> x) {
throw new RuntimeException();
}

static <U extends @Nullable Object> void nullableBound(Box<U> box) {
// :: error: (dereference.of.nullable)
takeExtends(wildcardBox(box)).toString();
U u = takeExtends(wildcardBox(box));
}

static <U extends @Nullable Object> void nonNullUse(Box<@NonNull U> box) {
takeExtends(wildcardBox(box)).toString();
@NonNull U u = takeExtends(wildcardBox(box));
}

static <U extends @Nullable Object> void nullableUse(Box<@Nullable U> box) {
// :: error: (argument)
@NonNull Object o = takeExtends(wildcardBox(box));
}

static <U extends Comparable<U>> void fBounded(Box<U> box, U other) {
takeExtends(wildcardBox(box)).compareTo(other);
}

static void string(Box<@Nullable String> box) {
// :: error: (dereference.of.nullable)
takeExtends(wildcardBox(box)).length();
@Nullable String s = takeExtends(wildcardBox(box));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,8 @@ private static BoundSet resolveWithCapture(
}

Set<AbstractType> upperBounds = ai.getBounds().upperBounds();
// Omit bounds that mention variables outside `as`, such as `alpha` in `ai <: alpha`.
upperBounds.removeIf(u -> !as.containsAll(u.getInferenceVariables()));
AbstractType upperBound = context.inferenceTypeFactory.glb(upperBounds);
if (upperBound != null) {
// `glb` returns its argument when `upperBounds` is a singleton, and that type is still
Expand Down
35 changes: 35 additions & 0 deletions framework/tests/all-systems/Issue8298.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Test case for https://github.com/typetools/checker-framework/issues/8298

import java.util.List;

public class Issue8298 {
static class Box<T> {}

static <T> Box<? extends T> wildcardBox(Box<T> b) {
throw new RuntimeException();
}

static <X> X takeExtends(Box<? extends X> x) {
throw new RuntimeException();
}

static <X> X takeList(Box<? extends List<X>> x) {
throw new RuntimeException();
}

static <U> void m(Box<U> box) {
takeExtends(wildcardBox(box));
}

static <U extends Comparable<U>> void fBounded(Box<U> box, U other) {
takeExtends(wildcardBox(box)).compareTo(other);
}

static void string(Box<String> box) {
takeExtends(wildcardBox(box)).length();
}

static void list(Box<List<String>> box) {
String s = takeList(wildcardBox(box));
}
}
Loading