skip inference for incompatible method references

EA-103416 - assert: PsiMethodReferenceCompatibilityConstraint.getSubstitutor
This commit is contained in:
Anna.Kozlova
2017-12-14 18:45:49 +01:00
parent aa1cb5fff1
commit 9e20e117d6
3 changed files with 16 additions and 4 deletions
@@ -249,10 +249,11 @@ public class PsiMethodReferenceCompatibilityConstraint implements ConstraintForm
final PsiResolveHelper helper = JavaPsiFacade.getInstance(methodReferenceExpression.getProject()).getResolveHelper();
final PsiType[] paramTypes =
member instanceof PsiMethod ? ((PsiMethod)member).getSignature(PsiSubstitutor.EMPTY).getParameterTypes() : PsiType.EMPTY_ARRAY;
LOG.assertTrue(paramTypes.length == signature.getParameterTypes().length ||
member instanceof PsiMethod && ((PsiMethod)member).isVarArgs(), "expr: " + methodReferenceExpression + "; " +
paramTypes.length + "; " +
Arrays.toString(signature.getParameterTypes()));
if (paramTypes.length != signature.getParameterTypes().length && !(member instanceof PsiMethod && ((PsiMethod)member).isVarArgs())) {
//inapplicable method reference
return PsiSubstitutor.EMPTY;
}
if (Arrays.deepEquals(signature.getParameterTypes(), paramTypes)) {
return PsiSubstitutor.EMPTY;
}
@@ -0,0 +1,10 @@
import java.util.function.IntFunction;
class Outer<K> {
public Outer() { }
{
//wrong number of parameters as well as a wrong expected type
final IntFunction<Outer[]> aNew = <error descr="Bad return type in method reference: cannot convert Outer to Outer[]">Outer::new</error>;
}
}
@@ -179,6 +179,7 @@ public class NewMethodRefHighlightingTest extends LightDaemonAnalyzerTestCase {
public void testConstructorReferenceWithVarargsParameters() { doTest(); }
public void testMethodReferenceSwallowedErrors() { doTest(); }
public void testConflictingVarargsFromFirstSearchWithNArityOfTheSecondSearch() { doTest(); }
public void testSkipInferenceForInapplicableMethodReference() { doTest(); }
public void testPreferErrorOnTopLevelToFailedSubstitutorOnNestedLevel() { doTest(); }