infer conditional expression type for incomplete calls (IDEA-171431)

This commit is contained in:
Anna Kozlova
2017-05-04 20:29:52 +03:00
parent 3c4fcef9fb
commit f3d0a39366
2 changed files with 6 additions and 5 deletions
@@ -890,7 +890,7 @@ public class InferenceSession {
if (argumentList != null) {
final MethodCandidateInfo.CurrentCandidateProperties properties = MethodCandidateInfo.getCurrentMethod(argumentList);
if (properties != null && properties.isApplicabilityCheck()) {
return getTypeByMethod(context, argumentList, properties.getMethod(), properties.isVarargs(), properties.getSubstitutor());
return getTypeByMethod(context, argumentList, properties.getMethod(), properties.isVarargs(), properties.getSubstitutor(), inferParent);
}
final JavaResolveResult result = ((PsiCall)gParent).resolveMethodGenerics();
@@ -901,7 +901,7 @@ public class InferenceSession {
}
if (element instanceof PsiMethod && (inferParent || !((PsiMethod)element).hasTypeParameters())) {
final boolean varargs = result instanceof MethodCandidateInfo && ((MethodCandidateInfo)result).isVarargs();
return getTypeByMethod(context, argumentList, result.getElement(), varargs, result.getSubstitutor());
return getTypeByMethod(context, argumentList, result.getElement(), varargs, result.getSubstitutor(), inferParent);
}
}
}
@@ -946,12 +946,13 @@ public class InferenceSession {
PsiExpressionList argumentList,
PsiElement parentMethod,
boolean varargs,
PsiSubstitutor substitutor) {
PsiSubstitutor substitutor,
boolean inferParent) {
if (parentMethod instanceof PsiMethod) {
final PsiParameter[] parameters = ((PsiMethod)parentMethod).getParameterList().getParameters();
if (parameters.length == 0) return null;
final PsiExpression[] args = argumentList.getExpressions();
if (!((PsiMethod)parentMethod).isVarArgs() && parameters.length != args.length) return null;
if (!((PsiMethod)parentMethod).isVarArgs() && parameters.length != args.length && !inferParent) return null;
PsiElement arg = context;
while (arg.getParent() instanceof PsiParenthesizedExpression) {
arg = arg.getParent();
@@ -1,7 +1,7 @@
class Test{
void test() {
B b = new B<error descr="'B(java.lang.String, java.lang.String)' in 'Test.B' cannot be applied to '(?)'">(true == false ? "bar" : null)</error>;
B b = new B<error descr="'B(java.lang.String, java.lang.String)' in 'Test.B' cannot be applied to '(java.lang.String)'">(true == false ? "bar" : null)</error>;
}
class B {