mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
overload resolution: compare functional interfaces for specific if they are not assignable (IDEA-140987)
This commit is contained in:
+5
-6
@@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
+24
@@ -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;
|
||||
}
|
||||
}
|
||||
+4
@@ -122,6 +122,10 @@ public class OverloadResolutionTest extends LightDaemonAnalyzerTestCase {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testProperUnrelatedFunctionalInterfacesTypesComparison() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
private void doTest() {
|
||||
doTest(true);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user