ensure potential compatible for pertinent to applicability: when number of parameters is wrong methods which are not potentially compatible are not filtered (IDEA-149103)

This commit is contained in:
Anna Kozlova
2015-12-09 19:28:03 +01:00
parent 92487fe273
commit c81d887251
3 changed files with 28 additions and 3 deletions

View File

@@ -125,7 +125,7 @@ public class MethodCandidateInfo extends CandidateInfo{
if (isToInferApplicability()) {
//already performed checks, so if inference failed, error message should be saved
if (myInferenceError != null) {
if (myInferenceError != null || !isPotentiallyCompatible()) {
return ApplicabilityLevel.NOT_APPLICABLE;
}
return isVarargs() ? ApplicabilityLevel.VARARGS : ApplicabilityLevel.FIXED_ARITY;
@@ -173,8 +173,15 @@ public class MethodCandidateInfo extends CandidateInfo{
final PsiParameter[] parameters = method.getParameterList().getParameters();
final PsiExpression[] expressions = ((PsiExpressionList)myArgumentList).getExpressions();
if (!isVarargs() && expressions.length != parameters.length) {
return true;
if (!isVarargs()) {
if (expressions.length != parameters.length) {
return false;
}
}
else {
if (expressions.length < parameters.length - 1) {
return false;
}
}
for (int i = 0; i < expressions.length; i++) {

View File

@@ -0,0 +1,14 @@
class Test {
public <T> void varargs(int i, String... p1) { }
public <T> void usage(String p1) { }
{
varargs<error descr="Cannot resolve method 'varargs()'">()</error>;
varargs(1);
varargs(1, "");
varargs(1, "", "");
usage<error descr="'usage(java.lang.String)' in 'Test' cannot be applied to '()'">()</error>;
usage("");
usage<error descr="'usage(java.lang.String)' in 'Test' cannot be applied to '(java.lang.String, java.lang.String)'">("", "")</error>;
}
}

View File

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