Skip to content

Commit

Permalink
Fix resolution of upper bounds for wildcards with lower bounds in `Jd…
Browse files Browse the repository at this point in the history
…tEnvironment`.

Given the declarations:
```
interface Parent {}
interface Child extends Parent {}
interface Generic<T extends Parent> {}
```

To satisfy declaration constraints, the upper bound for `Generic<? super Child>` should be `Parent` and not `Object`.

PiperOrigin-RevId: 681403152
  • Loading branch information
Googler authored and copybara-github committed Oct 2, 2024
1 parent a242b3e commit 5401dcb
Showing 1 changed file with 13 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -429,13 +429,19 @@ private TypeDescriptor getUpperBoundTypeDescriptor(
TypeDescriptor boundTypeDescriptor =
createTypeDescriptorWithNullability(
bound, bound.getTypeAnnotations(), inNullMarkedScope);
return typeBinding.isUpperbound()
? boundTypeDescriptor
: TypeDescriptors.get()
.javaLangObject
// Use the nullability of the lower bound for the upper bound of a lower bounded
// wildcard.
.toNullable(boundTypeDescriptor.isNullable());
if (typeBinding.isUpperbound()) {
return boundTypeDescriptor;
}

// Fallback to use type bounds to cover cases for lower bounds that also have upper bound
// type constraints as in the following example:
//
// interface Parent {}
// interface Child extends Parent {}
// interface Generic<T extends Parent> {}
//
// To satisfy declaration constraints, the upper bound for `Generic<? super Child>` should
// be `Parent`.
}
}
ITypeBinding[] bounds = typeBinding.getTypeBounds();
Expand Down

0 comments on commit 5401dcb

Please sign in to comment.