mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-19 13:02:30 +07:00
inference on incomplete code (EA-90195 - AIOOBE: PsiTypesUtil.getParameterType)
This commit is contained in:
@@ -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>() {
|
||||
|
||||
@@ -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) {}
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user