overload resolution: ensure all list of parameters is checked during most specific check of varargs methods (IDEA-150224)

This commit is contained in:
Anna Kozlova
2016-01-11 15:28:48 +01:00
parent 7e6b3916e8
commit 3baa03058b
3 changed files with 26 additions and 1 deletions

View File

@@ -1506,7 +1506,7 @@ public class InferenceSession {
LOG.assertTrue(parameters1.length == parameters2.length);
}
final int paramsLength = !varargs ? parameters1.length : parameters1.length - 1;
final int paramsLength = !varargs ? parameters1.length : Math.max(parameters1.length, parameters2.length) - 1;
for (int i = 0; i < paramsLength; i++) {
PsiType sType = getParameterType(parameters1, i, siteSubstitutor1, false);
PsiType tType = session.substituteWithInferenceVariables(getParameterType(parameters2, i, siteSubstitutor1, varargs));

View File

@@ -0,0 +1,21 @@
interface Node<<warning descr="Type parameter 'T' is never used">T</warning>> {
@SafeVarargs
static <T> Node<T> of(T value, Node<T>... children) {
System.out.println(value);
System.out.println(children);
return null;
}
@SafeVarargs
static <T1> Node<T1> of(T1... values) {
System.out.println(values);
return null;
}
static void test() {
Node.of(1, Node.of(2), Node.of(3));
Node.<Integer>of(1, Node.<Integer>of(2), Node.<Integer> of(3));
}
}

View File

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