new inference: reject methrefs with inconsistent number of parameters

(cherry picked from commit 9c41270192e140ed28067e2740333c6d3fa49bd2)
This commit is contained in:
anna
2013-11-18 20:00:50 +01:00
parent a9bc9bfb6d
commit 10439a10a0
3 changed files with 22 additions and 1 deletions

View File

@@ -98,10 +98,12 @@ public class PsiMethodReferenceCompatibilityConstraint implements ConstraintForm
for (int i = 1; i < targetParameters.length; i++) {
constraints.add(new TypeCompatibilityConstraint(psiSubstitutor.substitute(parameters[i - 1].getType()), GenericsUtil.eliminateWildcards(substitutor.substitute(targetParameters[i].getType()))));
}
} else {
} else if (targetParameters.length == parameters.length) {
for (int i = 0; i < targetParameters.length; i++) {
constraints.add(new TypeCompatibilityConstraint(psiSubstitutor.substitute(parameters[i].getType()), GenericsUtil.eliminateWildcards(substitutor.substitute(targetParameters[i].getType()))));
}
} else {
return false;
}
if (returnType != PsiType.VOID) {
if (applicableMethodReturnType == PsiType.VOID) {

View File

@@ -0,0 +1,15 @@
class Test {
interface I {
void m(Integer x1, Integer x2, Integer x3);
}
static class Foo {
static void foo() {}
}
<T> void bar(I i) {}
void test() {
bar<error descr="'bar(Test.I)' in 'Test' cannot be applied to '(<method reference>)'">(Foo::foo)</error>;
}
}

View File

@@ -78,6 +78,10 @@ public class NewMethodRefHighlightingTest extends LightDaemonAnalyzerTestCase {
doTest(false);
}
public void testAssertNumberOfParameters() throws Exception {
doTest(false);
}
private void doTest() {
doTest(false);
}