new inference: skip lambda return expression additional constraints during overload resolution

This commit is contained in:
Anna Kozlova
2015-04-29 18:32:06 +02:00
parent cf9dc657fc
commit c411468b07
3 changed files with 33 additions and 0 deletions

View File

@@ -299,6 +299,13 @@ public class InferenceSession {
for (int i = 0; i < args.length; i++) {
final PsiExpression arg = PsiUtil.skipParenthesizedExprDown(args[i]);
if (arg != null) {
if (MethodCandidateInfo.isOverloadCheck() && arg instanceof PsiLambdaExpression) {
for (Object expr : MethodCandidateInfo.ourOverloadGuard.currentStack()) {
if (PsiTreeUtil.getParentOfType((PsiElement)expr, PsiLambdaExpression.class) == arg) {
return;
}
}
}
final InferenceSession nestedCallSession = findNestedCallSession(arg);
final PsiType parameterType =
nestedCallSession.substituteWithInferenceVariables(getParameterType(parameters, i, siteSubstitutor, varargs));

View File

@@ -0,0 +1,22 @@
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import java.util.function.Function;
class MyTest {
interface I<T, E> {
List<E> m(Set<T> s);
}
<K, L>List<K> foo(I<K, L> i){return null;}
<K, H> List<K> bar(Runnable l) {return null;}
List<String> bar(Function<String, String> s) {return null;}
String baz(Set<Integer> b, String x) {return null;}
List<Integer> baz(Iterator<Integer> s, Iterator<Integer> i) {return null;}
{
List<Integer> l = foo(a -> bar(b -> b<ref>az(a, b)));
}
}

View File

@@ -43,6 +43,10 @@ public class TypeInference18Test extends ResolveTestCase {
doTestMethodCall();
}
public void testLambdaChainConflictResolution() throws Exception {
doTestMethodCall();
}
public void testCachedSubstitutionDuringOverloadResolution() throws Exception {
PsiReference ref = configureByFile("/codeInsight/daemonCodeAnalyzer/lambda/resolve/" + getTestName(false) + ".java");
assertNotNull(ref);