Skip to content

Commit

Permalink
Fix handling of primitives in TypesUtils#leastUpperBound (#5129)
Browse files Browse the repository at this point in the history
Summary:
The previous version would return incorrect lub in some cases, e.g.:
```
TypesUtils.leastUpperBound(t1=Integer, t2=int) == int
```
This is because int and Integer are assignable to each other, so just
checking assignability is not enough to figure out which type to return.
  • Loading branch information
artempyanykh committed Apr 29, 2022
1 parent 09457b6 commit 9ab1614
Showing 1 changed file with 4 additions and 2 deletions.
Expand Up @@ -869,9 +869,11 @@ public static TypeMirror leastUpperBound(
}
// Special case for primitives.
if (isPrimitive(t1) || isPrimitive(t2)) {
if (types.isAssignable(t1, t2)) {
// NOTE: we need to know which type is primitive because e.g. int and Integer are assignable
// to each other.
if (isPrimitive(t1) && types.isAssignable(t1, t2)) {
return t2;
} else if (types.isAssignable(t2, t1)) {
} else if (isPrimitive(t2) && types.isAssignable(t2, t1)) {
return t1;
} else {
Elements elements = processingEnv.getElementUtils();
Expand Down

0 comments on commit 9ab1614

Please sign in to comment.