Add test case for #5190

This commit is contained in:
Clément Fournier
2024-09-03 11:16:56 +02:00
parent 7ba88e9eba
commit 9d925b513d

View File

@ -454,4 +454,32 @@ public class BadIntersection {
info.methodType.formalParameters[0] shouldBe optOutEnum
}
}
parserTest("#5190 NPE in type inf") {
val (acu, spy) = parser.parseWithTypeInferenceSpy(
"""
interface Optional<T> {
static Optional<T> ofNullable(T t) {}
}
interface Map<K,V> {}
interface AttributeValue{}
public class Main {
private Optional<Map<String, AttributeValue>> loadForKey(final String key) {
return Optional.ofNullable(
Iterables.getOnlyElement(queryForKey(key), null)
);
}
}
""".trimIndent()
)
val (_, _, _) = acu.declaredTypeSignatures()
val (ofNullable) = acu.methodDeclarations().toList { it.genericSignature }
spy.shouldBeOk {
val info = acu.firstMethodCall().overloadSelectionInfo
info::isFailed shouldBe false
info.methodType shouldBeSomeInstantiationOf ofNullable
}
}
})