mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-18 09:34:34 +07:00
new inference: missed capture conversions for method references
This commit is contained in:
@@ -325,7 +325,7 @@ public class PsiMethodReferenceUtil {
|
||||
if (methodReturnType == null) {
|
||||
methodReturnType = JavaPsiFacade.getElementFactory(expression.getProject()).createType(containingClass, subst);
|
||||
}
|
||||
if (!TypeConversionUtil.isAssignable(interfaceReturnType, methodReturnType)) {
|
||||
if (!TypeConversionUtil.isAssignable(interfaceReturnType, PsiUtil.captureToplevelWildcards(methodReturnType, expression))) {
|
||||
return "Bad return type in method reference: cannot convert " + methodReturnType.getCanonicalText() + " to " + interfaceReturnType.getCanonicalText();
|
||||
}
|
||||
}
|
||||
|
||||
+9
-9
@@ -114,16 +114,16 @@ public class PsiMethodReferenceCompatibilityConstraint implements ConstraintForm
|
||||
return false;
|
||||
}
|
||||
|
||||
if (applicableMethodReturnType != null) {
|
||||
constraints.add(new TypeCompatibilityConstraint(returnType,
|
||||
session.substituteWithInferenceVariables(psiSubstitutor.substitute(applicableMethodReturnType))));
|
||||
}
|
||||
else if (applicableMember instanceof PsiClass || applicableMember instanceof PsiMethod && ((PsiMethod)applicableMember).isConstructor()) {
|
||||
final PsiElementFactory elementFactory = JavaPsiFacade.getElementFactory(applicableMember.getProject());
|
||||
if (applicableMethodReturnType == null &&
|
||||
(applicableMember instanceof PsiClass || applicableMember instanceof PsiMethod && ((PsiMethod)applicableMember).isConstructor())) {
|
||||
if (containingClass != null) {
|
||||
final PsiType classType = session.substituteWithInferenceVariables(elementFactory.createType(containingClass, psiSubstitutor));
|
||||
constraints.add(new TypeCompatibilityConstraint(returnType, classType));
|
||||
}
|
||||
applicableMethodReturnType = JavaPsiFacade.getElementFactory(applicableMember.getProject()).createType(containingClass, PsiSubstitutor.EMPTY);
|
||||
}
|
||||
}
|
||||
|
||||
if (applicableMethodReturnType != null) {
|
||||
final PsiType capturedReturnType = PsiUtil.captureToplevelWildcards(psiSubstitutor.substitute(applicableMethodReturnType), myExpression);
|
||||
constraints.add(new TypeCompatibilityConstraint(returnType, session.substituteWithInferenceVariables(capturedReturnType)));
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user