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
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,23 @@ public Type visitCapturedType(Type.CapturedType t, Type other) {
Type.WildcardType otherWildcard = GenericsUtils.asWildcard(other);
Type.WildcardType updatedWildcard;
if (otherWildcard != null) {
updatedWildcard = (Type.WildcardType) t.wildcard.accept(this, otherWildcard);
if (t.wildcard.kind == BoundKind.EXTENDS && otherWildcard.kind == BoundKind.UNBOUND) {
// Substitution can turn the capture's backing wildcard into an explicit extends
// wildcard while the corresponding declared wildcard remains unbounded. Its `type`
// field is just an Object placeholder; annotations must be restored from the implicit
// upper bound of its formal type variable instead.
Type.TypeVar formalTypeVariable = otherWildcard.bound;
if (formalTypeVariable == null) {
return updated;
}
Type updatedBound = t.wildcard.type.accept(this, formalTypeVariable.getUpperBound());
if (updatedBound == t.wildcard.type) {
return updated;
}
updatedWildcard = TYPE_METADATA_BUILDER.createWildcardType(t.wildcard, updatedBound);
} else {
updatedWildcard = (Type.WildcardType) t.wildcard.accept(this, otherWildcard);
}
} else if (t.wildcard.kind == BoundKind.EXTENDS) {
Type updatedBound = t.wildcard.type.accept(this, other);
if (updatedBound == t.wildcard.type) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,40 @@ void test(Foo<? extends U> f) {
.doTest();
}

@Test
public void issue1715() {
makeHelper()
.addSourceLines(
"Test.java",
"""
import org.jspecify.annotations.NullMarked;
import org.jspecify.annotations.Nullable;
@NullMarked
class Test {
interface I1<X> {}
interface I2<X, Y extends I1<X>> {
Y get();
}
I1<Object> crash(I2<Object, ?> i2) {
var i2var = i2;
return i2var.get();
}

interface NullableI1<X extends @Nullable Object> {}
interface NullableI2<
X extends @Nullable Object, Y extends NullableI1<@Nullable X>> {
Y get();
}
NullableI1<Object> incompatible(NullableI2<Object, ?> i2) {
var i2var = i2;
// BUG: Diagnostic contains: incompatible types
return i2var.get();
}
}
""")
.doTest();
}

@Test
public void wildcardCaptureLocals() {
makeHelper()
Expand Down
Loading