mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
lambda: check all return expressions for constraints
This commit is contained in:
+12
-3
@@ -595,6 +595,7 @@ public class PsiResolveHelperImpl implements PsiResolveHelper {
|
||||
final PsiSubstitutor subst = resolveResult.getSubstitutor();
|
||||
final PsiType returnType = subst.substitute(method.getReturnType());
|
||||
if (returnType != null && returnType != PsiType.VOID) {
|
||||
Pair<PsiType, ConstraintType> constraint = null;
|
||||
final List<PsiExpression> expressions = lambdaExpression.getReturnExpressions();
|
||||
for (final PsiExpression expression : expressions) {
|
||||
final boolean independent = LambdaUtil.isFreeFromTypeInferenceArgs(methodParameters, lambdaExpression, expression);
|
||||
@@ -621,12 +622,20 @@ public class PsiResolveHelperImpl implements PsiResolveHelper {
|
||||
if (exprType == null){
|
||||
return FAILED_INFERENCE;
|
||||
}
|
||||
Pair<PsiType, ConstraintType> constraint =
|
||||
|
||||
final Pair<PsiType, ConstraintType> returnExprConstraint =
|
||||
getSubstitutionForTypeParameterConstraint(typeParam, returnType, exprType, false, PsiUtil.getLanguageLevel(method));
|
||||
if (constraint != null) {
|
||||
return constraint; //todo check that all return statements lead to the same inference
|
||||
if (returnExprConstraint != null) {
|
||||
if (returnExprConstraint == FAILED_INFERENCE) return returnExprConstraint;
|
||||
if (constraint != null) {
|
||||
final PsiType leastUpperBound = GenericsUtil.getLeastUpperBound(constraint.getFirst(), returnExprConstraint.getFirst(), typeParam.getManager());
|
||||
constraint = new Pair<PsiType, ConstraintType>(leastUpperBound, ConstraintType.SUPERTYPE);
|
||||
} else {
|
||||
constraint = returnExprConstraint;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (constraint != null) return constraint;
|
||||
}
|
||||
for (PsiParameter parameter : methodParameters) {
|
||||
if (LambdaUtil.dependsOnTypeParams(parameter.getType(), lambdaExpression)) {
|
||||
|
||||
+25
@@ -1,3 +1,18 @@
|
||||
/*
|
||||
* Copyright 2000-2012 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import java.util.List;
|
||||
class Test1 {
|
||||
|
||||
@@ -23,6 +38,16 @@ class Test1 {
|
||||
bar2("", x -> x);
|
||||
|
||||
bar3(x -> x, "");
|
||||
|
||||
int ixc = 42;
|
||||
bar(x -> {
|
||||
if (ixc == 2) return "aaa";
|
||||
return x;
|
||||
});
|
||||
bar(x -> {
|
||||
if (ixc == 2) return x;
|
||||
return x;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user