mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-08 15:09:39 +07:00
new inference: functional parameterization should proceed to non-wildcard parameterization with partly ready parameterization, new spec (IDEA-131417)
(cherry picked from commit e7cf17fa45740d7f233ce426d9d78a3580399d8e)
This commit is contained in:
@@ -61,6 +61,9 @@ public class FunctionalInterfaceParameterizationUtil {
|
||||
return psiClassType instanceof PsiClassType ? getNonWildcardParameterization((PsiClassType)psiClassType) : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 18.5.3. Functional Interface Parameterization Inference
|
||||
*/
|
||||
private static PsiType getFunctionalTypeExplicit(PsiType psiClassType, PsiLambdaExpression expr) {
|
||||
final PsiParameter[] lambdaParams = expr.getParameterList().getParameters();
|
||||
if (psiClassType instanceof PsiIntersectionType) {
|
||||
@@ -115,15 +118,19 @@ public class FunctionalInterfaceParameterizationUtil {
|
||||
|
||||
final PsiClassType parameterization = elementFactory.createType(psiClass, newTypeParameters);
|
||||
|
||||
//If F<A'1, ..., A'm> is not a well-formed type (that is, the type arguments are not within their bounds),
|
||||
// or if F<A'1, ..., A'm> is not a subtype of F<A1, ..., Am>, no valid parameterization exists.
|
||||
if (!isWellFormed(psiClass, typeParameters, newTypeParameters)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
//Otherwise, the inferred parameterization is either F<A'1, ..., A'm>, if all the type arguments are types,
|
||||
if (!TypeConversionUtil.containsWildcards(parameterization) && psiClassType.isAssignableFrom(parameterization)) {
|
||||
return parameterization;
|
||||
}
|
||||
|
||||
return getNonWildcardParameterization((PsiClassType)psiClassType);
|
||||
//or the non-wildcard parameterization (§9.8) of F<A'1, ..., A'm>, if one or more type arguments are still wildcards.
|
||||
return getNonWildcardParameterization(parameterization);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
import java.util.function.Function;
|
||||
|
||||
class Test {
|
||||
static void foo(Function<? super String, ? extends Number> f) {}
|
||||
|
||||
static void test() {
|
||||
foo((Object o) -> o.hashCode());
|
||||
}
|
||||
}
|
||||
@@ -36,6 +36,10 @@ public class FunctionalTypeWildcardParameterizationTest extends LightDaemonAnaly
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testNonWildcardParameterizationForInferredButStillWildcardParameterization() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
private void doTest() {
|
||||
IdeaTestUtil.setTestVersion(JavaSdkVersion.JDK_1_8, getModule(), getTestRootDisposable());
|
||||
doTest(BASE_PATH + "/" + getTestName(false) + ".java", false, false);
|
||||
|
||||
Reference in New Issue
Block a user