SOE with numeric conditional expressions when expression inside is not standalone

EA-78419 - SOE: InferenceSessionContainer.infer
This commit is contained in:
Anna Kozlova
2016-01-27 13:54:28 +03:00
parent ec89fa2295
commit c06f66ab26
4 changed files with 44 additions and 8 deletions

View File

@@ -151,7 +151,7 @@ public class InferenceSessionContainer {
}
@Nullable
private static InferenceSession startTopLevelInference(PsiCall topLevelCall) {
private static InferenceSession startTopLevelInference(final PsiCall topLevelCall) {
final JavaResolveResult result = topLevelCall.resolveMethodGenerics();
if (result instanceof MethodCandidateInfo) {
final PsiMethod method = ((MethodCandidateInfo)result).getElement();
@@ -159,11 +159,16 @@ public class InferenceSessionContainer {
final PsiExpressionList topLevelCallArgumentList = topLevelCall.getArgumentList();
LOG.assertTrue(topLevelCallArgumentList != null, topLevelCall);
final PsiExpression[] topLevelArguments = topLevelCallArgumentList.getExpressions();
final InferenceSession topLevelSession =
new InferenceSession(method.getTypeParameters(), ((MethodCandidateInfo)result).getSiteSubstitutor(), topLevelCall.getManager(), topLevelCall);
topLevelSession.initExpressionConstraints(topLevelParameters, topLevelArguments, topLevelCall, method, ((MethodCandidateInfo)result).isVarargs());
topLevelSession.infer(topLevelParameters, topLevelArguments, topLevelCall, ((MethodCandidateInfo)result).createProperties());
return topLevelSession;
return PsiResolveHelper.ourGraphGuard.doPreventingRecursion(topLevelCall, true, new Computable<InferenceSession>() {
@Override
public InferenceSession compute() {
final InferenceSession topLevelSession =
new InferenceSession(method.getTypeParameters(), ((MethodCandidateInfo)result).getSiteSubstitutor(), topLevelCall.getManager(), topLevelCall);
topLevelSession.initExpressionConstraints(topLevelParameters, topLevelArguments, topLevelCall, method, ((MethodCandidateInfo)result).isVarargs());
topLevelSession.infer(topLevelParameters, topLevelArguments, topLevelCall, ((MethodCandidateInfo)result).createProperties());
return topLevelSession;
}
});
}
return null;
}
@@ -198,7 +203,8 @@ public class InferenceSessionContainer {
PsiCall top = null;
PsiElement parent = PsiTreeUtil.getParentOfType(context,
PsiExpressionList.class,
PsiLambdaExpression.class,
PsiLambdaExpression.class,
PsiConditionalExpression.class,
PsiCodeBlock.class,
PsiCall.class);
while (true) {
@@ -227,6 +233,10 @@ public class InferenceSessionContainer {
}
}
if (parent instanceof PsiConditionalExpression && !PsiPolyExpressionUtil.isPolyExpression((PsiExpression)parent)) {
break;
}
if (parent instanceof PsiLambdaExpression && LambdaUtil.getFunctionalTypeMap().containsKey(parent)) {
break;
}

View File

@@ -161,7 +161,15 @@ public class PsiMethodCallExpressionImpl extends ExpressionPsiElement implements
final JavaResolveResult[] results = methodExpression.multiResolve(false);
LanguageLevel languageLevel = PsiUtil.getLanguageLevel(call);
final PsiExpressionList parentArgList = languageLevel.isAtLeast(LanguageLevel.JDK_1_8) ? PsiTreeUtil.getParentOfType(call, PsiExpressionList.class) : null;
final PsiExpressionList parentArgList;
if (languageLevel.isAtLeast(LanguageLevel.JDK_1_8)) {
final PsiElement callParent = PsiUtil.skipParenthesizedExprUp(call.getParent());
parentArgList = callParent instanceof PsiConditionalExpression && !PsiPolyExpressionUtil.isPolyExpression((PsiExpression)callParent)
? null : PsiTreeUtil.getParentOfType(call, PsiExpressionList.class);
}
else {
parentArgList = null;
}
final MethodCandidateInfo.CurrentCandidateProperties properties = MethodCandidateInfo.getCurrentMethod(parentArgList);
final boolean genericMethodCall = properties != null && properties.getInfo().isToInferApplicability();

View File

@@ -0,0 +1,14 @@
class C {
static <M extends Integer> M foo() {
return null;
}
<G> G bar(G g, G gg) {
return g;
}
void m(boolean b){
bar(b ? foo() : null, foo());
}
}

View File

@@ -367,6 +367,10 @@ public class GraphInferenceHighlightingTest extends LightDaemonAnalyzerTestCase
doTest();
}
public void testStopAtStandaloneConditional() throws Exception {
doTest();
}
private void doTest() throws Exception {
doTest(false);
}