inference: treeWalkUp if overload is done under current argumentList caused by lambda parameter type inference (IDEA-157676)

This commit is contained in:
Anna Kozlova
2016-06-22 10:30:07 +03:00
parent 1c52cb7fd6
commit a330f9c2f7
3 changed files with 25 additions and 1 deletions

View File

@@ -69,7 +69,12 @@ public class InferenceSessionContainer {
if (parent instanceof PsiCall) {
final PsiExpressionList argumentList = ((PsiCall)parent).getArgumentList();
final MethodCandidateInfo.CurrentCandidateProperties properties = MethodCandidateInfo.getCurrentMethod(argumentList);
if (properties != null && !properties.isApplicabilityCheck() && !MethodCandidateInfo.isOverloadCheck()) {
//overload resolution can't depend on outer call => should not traverse to top
if (properties != null && !properties.isApplicabilityCheck() &&
//in order to to avoid caching of candidates's errors on parent (!) , so check for overload resolution is left here
//But overload resolution can depend on type of lambda parameter. As it can't depend on lambda body,
//traversing down would stop at lambda level and won't take into account overloaded method
!MethodCandidateInfo.ourOverloadGuard.currentStack().contains(argumentList)) {
final PsiCall topLevelCall = PsiResolveHelper.ourGraphGuard.doPreventingRecursion(parent, false,
new Computable<PsiCall>() {
@Override

View File

@@ -0,0 +1,12 @@
import java.util.stream.Collectors;
import java.util.stream.Stream;
class Test {
public void foo(Stream<String> stream) {
stream.collect(Collectors.toMap(null, e -> bar(e)));
}
public String bar(int entity) { return null; }
public String bar(String entity) { return null; }
}

View File

@@ -173,11 +173,18 @@ public class Java8ExpressionsCheckTest extends LightDaemonAnalyzerTestCase {
doTestAllMethodCallExpressions();
}
public void testOverloadResolutionInsideLambdaInsideNestedCall() throws Exception {
doTestAllMethodCallExpressions();
}
private void doTestAllMethodCallExpressions() {
configureByFile(BASE_PATH + "/" + getTestName(false) + ".java");
final Collection<PsiCallExpression> methodCallExpressions = PsiTreeUtil.findChildrenOfType(getFile(), PsiCallExpression.class);
for (PsiCallExpression expression : methodCallExpressions) {
getPsiManager().dropResolveCaches();
if (expression instanceof PsiMethodCallExpression) {
assertNotNull("Failed to resolve: " + expression.getText(), expression.resolveMethod());
}
assertNotNull("Failed inference for: " + expression.getText(), expression.getType());
}