java method reference inference: keep additional inference variables when second search is not possible (IDEA-252839)

GitOrigin-RevId: 358b0408221aaf6e51dbf87867ae8f33ba0d0fde
This commit is contained in:
Anna Kozlova
2020-10-28 13:54:41 +01:00
committed by intellij-monorepo-bot
parent 2c2bce389a
commit 9970306c8f
3 changed files with 23 additions and 1 deletions

View File

@@ -209,7 +209,12 @@ public class PsiMethodReferenceCompatibilityConstraint implements ConstraintForm
if (qContainingClass != null && PsiUtil.isRawSubstitutor(qContainingClass, qualifierResolveResult.getSubstitutor())) {
//15.13.1 If there exist a parameterization, then it would be used to search, the *raw type* would be used otherwise
if (getParameterization(signature, qualifierResolveResult, method, myExpression, qContainingClass) == null) {
referencedMethodReturnType = TypeConversionUtil.erasure(referencedMethodReturnType);
if (!PsiMethodReferenceUtil.isSecondSearchPossible(signature.getParameterTypes(), qualifierResolveResult, myExpression)) {
session.initBounds(myExpression, qContainingClass.getTypeParameters());
}
else {
referencedMethodReturnType = TypeConversionUtil.erasure(referencedMethodReturnType);
}
}
}

View File

@@ -0,0 +1,16 @@
import java.util.*;
interface Foo<T> {
static <E> Foo<E> of(E e1) {
return null;
}
T get(int i);
}
class MainTest {
{
Optional.of("one,two").map(Foo::<String>of).get().get(0).split(",");
Optional.of("one,two").map(Foo::of).get().get(0).split(",");
}
}

View File

@@ -198,6 +198,7 @@ public class NewMethodRefHighlightingTest extends LightDaemonAnalyzerTestCase {
public void testCreateMethodFromMethodRefApplicability() { doTest(); }
public void testErrorMessageOnTopCallWhenFunctionalInterfaceIsNotInferred() { doTest(); }
public void testReferencesToPolymorphicMethod() { doTest(); }
public void testTypeArgumentsOnFirstSearchAccessibleMethod() { doTest(); }
private void doTest() {
doTest(false);