method references: site substitution for method references without receiver (IDEA-134261)

This commit is contained in:
Anna Kozlova
2014-12-12 20:57:02 +01:00
parent ab8e96f1d3
commit 482de672ef
5 changed files with 24 additions and 5 deletions

View File

@@ -1101,7 +1101,7 @@ public class InferenceSession {
for (int i = 0; i < functionalMethodParameters.length; i++) {
final PsiType pType = signature.getParameterTypes()[i];
addConstraint(new TypeCompatibilityConstraint(substituteWithInferenceVariables(getParameterType(parameters, i, PsiSubstitutor.EMPTY, varargs)),
addConstraint(new TypeCompatibilityConstraint(substituteWithInferenceVariables(getParameterType(parameters, i, qualifierResolveResult.getSubstitutor(), varargs)),
PsiImplUtil.normalizeWildcardTypeByPosition(pType, reference)));
}
}

View File

@@ -39,6 +39,6 @@ class MyTest1 {
static void foo(I3 i) {}
static {
foo<error descr="Ambiguous method call: both 'MyTest1.foo(I1)' and 'MyTest1.foo(I2)' match">(Foo::new)</error>;
foo<error descr="Cannot resolve method 'foo(<method reference>)'">(Foo::new)</error>;
}
}

View File

@@ -29,10 +29,10 @@ class Test {
static void meth4(I3 s) { }
static {
meth1(<error descr="Inferred type 'java.lang.String' for type parameter 'X' is not within its bound; should extend 'java.lang.Number'">Foo::new</error>);
meth1(Foo::<error descr="Cannot resolve constructor 'Foo'">new</error>);
meth2(Foo::new);
meth3(<error descr="Inferred type 'java.lang.Object' for type parameter 'X' is not within its bound; should extend 'java.lang.Number'">Foo::new</error>);
meth4<error descr="Ambiguous method call: both 'Test.meth4(I1)' and 'Test.meth4(I2)' match">(Foo::new)</error>;
meth3(Foo::<error descr="Cannot resolve constructor 'Foo'">new</error>);
meth4<error descr="Cannot resolve method 'meth4(<method reference>)'">(Foo::new)</error>;
meth1(<error descr="Inferred type 'java.lang.String' for type parameter 'X' is not within its bound; should extend 'java.lang.Number'">Test::foo</error>);
meth2(Test::foo);

View File

@@ -0,0 +1,15 @@
import java.util.*;
import java.util.function.Consumer;
class Test {
public void foo(final Logic<String> logic, Set<Map<String, String>> models) {
final Consumer<Map<String, String>> action = logic::declareField;
}
private static class Logic<E> {
public <T> void declareField(Map<E, T> field) {}
}
}

View File

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