Fix #5167 - issue with type projection

This commit is contained in:
Clément Fournier
2024-08-24 16:48:03 +02:00
parent dcee6e6900
commit da864aeccd
2 changed files with 44 additions and 0 deletions

View File

@@ -1170,6 +1170,13 @@ public final class TypeOps {
} else if (!upwards) {
// If Ai is a type that mentions a restricted type variable, then Ai' is undefined.
return NO_DOWN_PROJECTION;
} else if (u instanceof JWildcardType) {
// The rest of this function, below, treats u as the bound of a wildcard,
// but if u is already a wildcard (and therefore ai was a wildcard), we
// are already done.
newTargs.add(u);
change = true;
continue;
}
change = true;

View File

@@ -95,7 +95,44 @@ class TypeOpsTest : FunSpec({
}
test("#5167 problem in projection") {
val (acu, spy) = javaParser.parseWithTypeInferenceSpy(
"""
import java.lang.annotation.Annotation;
interface Bar<T> {
Baz<T> getBaz();
}
interface Predicate<T> {
boolean check(T t);
}
interface Stream<T>{
T findSome();
}
interface Baz<T>{
Stream<Bar<? super T>> filterMethods(Predicate<? super T> p);
}
class Foo {
private static Bar<?> foo(
Bar<?> type, Class<? extends Annotation> annotation, boolean required) {
var method = type.getBaz().filterMethods(m -> true).findSome();
return method;
}
}
""".trimIndent()
)
val (barT) = acu.declaredTypeSignatures()
val methodId = acu.varId("method")
spy.shouldBeOk {
methodId shouldHaveType barT[`?`]
}
}
}
}
})