new inference: include lifting constraint when parent call is being investigated

(cherry picked from commit aaeafcdce1c8d49512cc1fece17afb3e1705492e)
This commit is contained in:
anna
2013-11-21 12:27:36 +01:00
parent 45cf19cae3
commit fc58e5e0af
3 changed files with 31 additions and 9 deletions

View File

@@ -80,9 +80,8 @@ public class ExpressionCompatibilityConstraint extends InputOutputConstraintForm
final PsiExpressionList argumentList = ((PsiCallExpression)myExpression).getArgumentList();
if (argumentList != null) {
final Pair<PsiMethod,PsiSubstitutor> pair = MethodCandidateInfo.getCurrentMethod(argumentList);
if (pair != null) return true;
final JavaResolveResult resolveResult = ((PsiCallExpression)myExpression).resolveMethodGenerics();
final PsiMethod method = (PsiMethod)resolveResult.getElement();
final JavaResolveResult resolveResult = pair == null ? ((PsiCallExpression)myExpression).resolveMethodGenerics() : null;
final PsiMethod method = pair != null ? pair.first : (PsiMethod)resolveResult.getElement();
PsiType returnType = null;
PsiTypeParameter[] typeParams = null;
if (method != null && !method.isConstructor()) {
@@ -107,12 +106,16 @@ public class ExpressionCompatibilityConstraint extends InputOutputConstraintForm
session.addCapturedVariable(typeParam);
}
PsiSubstitutor substitutor = PsiSubstitutor.EMPTY;
if (method != null) {
InferenceSession callSession = new InferenceSession(typeParams, ((MethodCandidateInfo)resolveResult).getSiteSubstitutor(), myExpression.getManager());
final PsiExpression[] args = argumentList.getExpressions();
final PsiParameter[] parameters = method.getParameterList().getParameters();
callSession.initExpressionConstraints(parameters, args, myExpression);
substitutor = callSession.infer(parameters, args, myExpression, LiftParameterTypeInferencePolicy.INSTANCE);
if (pair == null) {
if (method != null) {
InferenceSession callSession = new InferenceSession(typeParams, ((MethodCandidateInfo)resolveResult).getSiteSubstitutor(), myExpression.getManager());
final PsiExpression[] args = argumentList.getExpressions();
final PsiParameter[] parameters = method.getParameterList().getParameters();
callSession.initExpressionConstraints(parameters, args, myExpression);
substitutor = callSession.infer(parameters, args, myExpression, LiftParameterTypeInferencePolicy.INSTANCE);
}
} else {
substitutor = pair.second;
}
final PsiType capturedReturnType = myExpression instanceof PsiMethodCallExpression
? PsiMethodCallExpressionImpl.captureReturnType((PsiMethodCallExpression)myExpression, method, returnType, substitutor)

View File

@@ -0,0 +1,15 @@
class Test {
static class SuperFoo<X> {}
static class Foo<X extends Number> extends SuperFoo<X> {}
interface I<Y> {
SuperFoo<Y> m();
}
<R> SuperFoo<R> foo(I<R> ax) { return null; }
SuperFoo<String> ls = foo(() -> new Foo<<error descr="Type parameter 'java.lang.String' is not within its bound; should extend 'java.lang.Number'"></error>>());
SuperFoo<Integer> li = foo(() -> new Foo<>());
SuperFoo<?> lw = foo(() -> new Foo<>());
}

View File

@@ -74,6 +74,10 @@ public class NewLambdaHighlightingTest extends LightDaemonAnalyzerTestCase {
doTest();
}
public void testIncludeConstraintsWhenParentMethodIsDuringCalculation() throws Exception {
doTest();
}
private void doTest() {
doTest(false);
}