new overload resolution: don't treat array type of functional interfaces as functional interface (IDEA-148726)

This commit is contained in:
Anna Kozlova
2015-12-02 16:57:49 +01:00
parent 80ff639c5d
commit e8111b751e
3 changed files with 24 additions and 2 deletions

View File

@@ -1510,7 +1510,9 @@ public class InferenceSession {
for (int i = 0; i < paramsLength; i++) {
PsiType sType = getParameterType(parameters1, i, siteSubstitutor1, false);
PsiType tType = session.substituteWithInferenceVariables(getParameterType(parameters2, i, siteSubstitutor1, varargs));
if (LambdaUtil.isFunctionalType(sType) && LambdaUtil.isFunctionalType(tType) && !relates(sType, tType)) {
if (sType instanceof PsiClassType &&
tType instanceof PsiClassType &&
LambdaUtil.isFunctionalType(sType) && LambdaUtil.isFunctionalType(tType) && !relates(sType, tType)) {
if (!isFunctionalTypeMoreSpecific(sType, tType, session, args[i])) {
return false;
}
@@ -1590,7 +1592,8 @@ public class InferenceSession {
final List<PsiExpression> returnExpressions = LambdaUtil.getReturnExpressions((PsiLambdaExpression)arg);
if (LambdaUtil.isFunctionalType(sReturnType) && LambdaUtil.isFunctionalType(tReturnType) &&
if (sReturnType instanceof PsiClassType && tReturnType instanceof PsiClassType &&
LambdaUtil.isFunctionalType(sReturnType) && LambdaUtil.isFunctionalType(tReturnType) &&
!TypeConversionUtil.isAssignable(TypeConversionUtil.erasure(sReturnType), TypeConversionUtil.erasure(tReturnType)) &&
!TypeConversionUtil.isAssignable(TypeConversionUtil.erasure(tReturnType), TypeConversionUtil.erasure(sReturnType))) {

View File

@@ -0,0 +1,15 @@
class Test {
private static <T> void test(Class<T> cls, Runnable... objs) {
System.out.println(cls);
System.out.println(objs);
}
private static <K> void <warning descr="Private method 'test(K, java.lang.Runnable...)' is never used">test</warning>(K obj, Runnable... objs) {
System.out.println(obj);
System.out.println(objs);
}
public static void main(String[] args) {
test(String.class, new Runnable[1]);
}
}

View File

@@ -179,6 +179,10 @@ public class OverloadResolutionTest extends LightDaemonAnalyzerTestCase {
doTest();
}
public void testFunctionalInterfacesAtVarargsPositionMostSpecificCheck() throws Exception {
doTest();
}
private void doTest() {
doTest(true);
}