java inference: stop when argument has no associated formal parameter

GitOrigin-RevId: cbc4e435f6e03bd06eac4dcf21196bdd61dc6c3d
This commit is contained in:
Anna.Kozlova
2019-12-03 16:04:11 +00:00
committed by intellij-monorepo-bot
parent d93efc10e8
commit 21e434894f
3 changed files with 20 additions and 1 deletions
@@ -276,7 +276,7 @@ public class InferenceSession {
}
private static PsiType getParameterType(PsiParameter[] parameters, int i, @Nullable PsiSubstitutor substitutor, boolean varargs) {
if (substitutor == null) return null;
if (substitutor == null || !varargs && i >= parameters.length) return null;
return substitutor.substitute(PsiTypesUtil.getParameterType(parameters, i, varargs));
}
@@ -391,6 +391,7 @@ public class InferenceSession {
if (arg != null) {
final PsiSubstitutor nestedSubstitutor = myInferenceSessionContainer.findNestedSubstitutor(arg, myInferenceSubstitution);
final PsiType parameterType = nestedSubstitutor.substitute(getParameterType(parameters, i, siteSubstitutor, varargs));
if (parameterType == null) continue;
if (!isPertinentToApplicability(arg, parentMethod)) {
ExpressionCompatibilityConstraint compatibilityConstraint = new ExpressionCompatibilityConstraint(arg, parameterType);
if (arg instanceof PsiFunctionalExpression && ignoreLambdaConstraintTree(arg) || dependsOnIgnoredConstraint(ignoredConstraints, compatibilityConstraint)) {
@@ -0,0 +1,17 @@
import java.util.function.UnaryOperator;
import java.util.stream.Stream;
class Main {
static class A {
A next(){return null;}
int x;
}
static boolean isGood(A a) {
return true;
}
{
Stream.iterate(new A(), (UnaryOperator<A>) <error descr="Bad return type in method reference: cannot convert boolean to Main.A">Main::isGood</error>, a -> a.<error descr="Cannot resolve method 'next()'">next</error>()).filter(a -> a.x < 3).forEach(System.out::println);
}
}
@@ -61,6 +61,7 @@ public class GraphInferenceHighlightingTest extends LightDaemonAnalyzerTestCase
public void testGrandParentTypeParams() { doTest(); }
public void testDeepCallsChain() { doTest(); }
public void testArrayPassedToVarargsMethod() { doTest(); }
public void testWrongNumberOfParametersWithLambdaOnUnexpectedPlace() { doTest(); }
public void testIDEA121055() { doTest(); }
public void testTargetTypeByAnonymousClass() { doTest(); }
public void testStaticInheritorsAmbiguity() { doTest(); }