mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-08 06:39:38 +07:00
new inference: include lifting constraint when parent call is being investigated
(cherry picked from commit aaeafcdce1c8d49512cc1fece17afb3e1705492e)
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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<>());
|
||||
}
|
||||
@@ -74,6 +74,10 @@ public class NewLambdaHighlightingTest extends LightDaemonAnalyzerTestCase {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testIncludeConstraintsWhenParentMethodIsDuringCalculation() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
private void doTest() {
|
||||
doTest(false);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user