new inference: method refs: accept qualifier substitutor when nothing more could be inferred

This commit is contained in:
Anna Kozlova
2014-02-27 18:29:55 +01:00
parent e0f2061c1c
commit 66a8dedb8c
4 changed files with 21 additions and 1 deletions

View File

@@ -499,6 +499,7 @@ public class PsiMethodReferenceExpressionImpl extends PsiReferenceExpressionBase
final PsiClass pClass = pResult.getElement();
final PsiSubstitutor receiverSubstitutor = pClass != null ? TypeConversionUtil.getClassSubstitutor(containingClass, pClass, pResult.getSubstitutor()) : null;
if (receiverSubstitutor != null) {
if (!method.hasTypeParameters() && signature.getParameterTypes().length == 1) return receiverSubstitutor;
psiSubstitutor = receiverSubstitutor;
}
}

View File

@@ -29,7 +29,7 @@ class MyTest {
}
public static void main(String[] args) {
foo<error descr="Ambiguous method call: both 'MyTest.foo(I1)' and 'MyTest.foo(I2)' match">(Foo::m)</error>;
foo<error descr="Ambiguous method call: both 'MyTest.foo(I2)' and 'MyTest.foo(I3)' match">(Foo::m)</error>;
}
}

View File

@@ -0,0 +1,15 @@
class Test {
static class Foo<X> {
X m() { return null;}
}
interface I {
Foo<Object> _i(Foo<String> fs);
}
static void foo(I i) { }
{
foo(<error descr="Bad return type in method reference: cannot convert java.lang.String to Test.Foo<java.lang.Object>">Foo::m</error>);
}
}

View File

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