inference on incomplete code (EA-90195 - AIOOBE: PsiTypesUtil.getParameterType)

This commit is contained in:
Anna.Kozlova
2016-10-20 14:07:51 +02:00
parent 357ee4e52f
commit 12554167e7
3 changed files with 27 additions and 2 deletions

View File

@@ -17,7 +17,6 @@ package com.intellij.psi.impl.source.resolve.graphInference;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.util.Computable;
import com.intellij.openapi.util.Ref;
import com.intellij.psi.*;
import com.intellij.psi.impl.source.resolve.ParameterTypeInferencePolicy;
import com.intellij.psi.impl.source.resolve.graphInference.constraints.ExpressionCompatibilityConstraint;
@@ -174,7 +173,11 @@ public class InferenceSessionContainer {
final int idx = LambdaUtil.getLambdaIdx(call.getArgumentList(), gParent);
final PsiMethod method = call.resolveMethod();
if (method != null && idx > -1) {
final PsiType parameterType = PsiTypesUtil.getParameterType(method.getParameterList().getParameters(), idx, true);
final PsiParameter[] methodParameters = method.getParameterList().getParameters();
if (methodParameters.length == 0) {
break;
}
final PsiType parameterType = PsiTypesUtil.getParameterType(methodParameters, idx, true);
final PsiType parameterTypeInTermsOfSession = initialInferenceState.getInferenceSubstitutor().substitute(parameterType);
final PsiType lambdaTargetType = compoundInitialState.getInitialSubstitutor().substitute(parameterTypeInTermsOfSession);
return LambdaUtil.performWithLambdaTargetType((PsiLambdaExpression)gParent, lambdaTargetType, new Producer<PsiSubstitutor>() {

View File

@@ -0,0 +1,18 @@
import java.util.Optional;
import java.util.function.UnaryOperator;
class Test<T> {
private void example() {
update(x -> x.flatMap<error descr="'flatMap()' in 'Test' cannot be applied to '(<lambda expression>)'">(y -> getEmpty())</error>);
}
private <J> Test<J> flatMap() {
return null;
}
private <K> Optional<K> getEmpty() {
return Optional.empty();
}
void update(UnaryOperator<Test<Integer>> u) {}
}

View File

@@ -35,6 +35,10 @@ public class NewInferenceCollectingAdditionalConstraintsTest extends LightDaemon
doTest();
}
public void testIncompleteResolveDuringNestedChecks() throws Exception {
doTest();
}
private void doTest() {
IdeaTestUtil.setTestVersion(JavaSdkVersion.JDK_1_8, getModule(), getTestRootDisposable());
doTest(BASE_PATH + "/" + getTestName(false) + ".java", true, false);