overload resolution: compare functional interfaces for specific if they are not assignable (IDEA-140987)

This commit is contained in:
Anna Kozlova
2015-06-02 17:58:59 +02:00
parent 788906a0b3
commit fc175ce1a8
3 changed files with 33 additions and 6 deletions
@@ -1360,17 +1360,16 @@ public class InferenceSession {
for (int i = 0; i < paramsLength; i++) {
PsiType sType = getParameterType(parameters1, i, PsiSubstitutor.EMPTY, false);
PsiType tType = session.substituteWithInferenceVariables(getParameterType(parameters2, i, PsiSubstitutor.EMPTY, varargs));
if (session.isProperType(sType) && session.isProperType(tType)) {
if (!TypeConversionUtil.isAssignable(tType, sType)) {
return false;
}
continue;
}
if (LambdaUtil.isFunctionalType(sType) && LambdaUtil.isFunctionalType(tType) && !relates(sType, tType)) {
if (!isFunctionalTypeMoreSpecific(sType, tType, session, args[i])) {
return false;
}
} else {
if (session.isProperType(tType)) {
if (!TypeConversionUtil.isAssignable(tType, sType)) {
return false;
}
}
session.addConstraint(new StrictSubtypingConstraint(tType, sType));
}
}
@@ -0,0 +1,24 @@
import java.util.function.Consumer;
import java.util.function.Function;
class Test {
private static <T> T withProject(final Function<ProjectEnvironment, T> calculation) {
System.out.println(calculation);
return null;
}
private static <T> T <warning descr="Private method 'withProject(java.util.function.Consumer<ProjectEnvironment>)' is never used">withProject</warning>(final Consumer<ProjectEnvironment> calculation){
System.out.println(calculation);
return null;
}
public static String foo() {
return withProject(ProjectEnvironment::getProject);
}
}
class ProjectEnvironment {
String getProject() {
return null;
}
}
@@ -122,6 +122,10 @@ public class OverloadResolutionTest extends LightDaemonAnalyzerTestCase {
doTest();
}
public void testProperUnrelatedFunctionalInterfacesTypesComparison() throws Exception {
doTest();
}
private void doTest() {
doTest(true);
}