method references: don't infer Object when no constraint exist for 'raw' reference (IDEA-171922)

This commit is contained in:
Anna.Kozlova
2017-04-26 16:28:04 +02:00
parent e2ceb575a2
commit c4d213ba26
3 changed files with 23 additions and 0 deletions
@@ -252,6 +252,10 @@ public class PsiMethodReferenceCompatibilityConstraint implements ConstraintForm
LOG.assertTrue(paramTypes.length == signature.getParameterTypes().length, "expr: " + methodReferenceExpression + "; " +
paramTypes.length + "; " +
Arrays.toString(signature.getParameterTypes()));
if (Arrays.deepEquals(signature.getParameterTypes(), paramTypes)) {
return PsiSubstitutor.EMPTY;
}
psiSubstitutor = helper.inferTypeArguments(PsiTypesUtil.filterUnusedTypeParameters(qContainingClass.getTypeParameters(), paramTypes),
paramTypes,
signature.getParameterTypes(),
@@ -0,0 +1,18 @@
import java.util.List;
import java.util.function.Function;
class Foo<T extends Comparable<T>> {
public Foo(final Foo<T> tuple) { }
{
List<Foo<T>> l = bar(Foo::new);
}
public<U> List<U> bar(Function<Foo<T>, U> mapper) {
return null;
}
}
@@ -172,6 +172,7 @@ public class NewMethodRefHighlightingTest extends LightDaemonAnalyzerTestCase {
public void testIncludeOnlyTypeParametersUsedInParameterTypesExcludeThoseUsedInReturnOnly() { doTest(); }
public void testMethodREfToContainingMethodWithGenericParam() { doTest(); }
public void testDistinguishCapturedWildcardsByDifferentParameters() throws Exception { doTest(); }
public void testConstructorRefOnClassWithRecursiveTypeParameter() throws Exception { doTest(); }
private void doTest() {
doTest(false);