new inference: nested varargs

(cherry picked from commit 0d293e439ffcbe97db98c1a1b8072e798d94323e)
This commit is contained in:
Anna Kozlova
2014-03-11 15:22:18 +01:00
parent 144684ba22
commit 465325a6a6
8 changed files with 79 additions and 5 deletions

View File

@@ -105,6 +105,9 @@ public class MethodCandidateInfo extends CandidateInfo{
@ApplicabilityLevelConstant
public int getPertinentApplicabilityLevel() {
if (myArgumentList == null || !PsiUtil.isLanguageLevel8OrHigher(myArgumentList)) {
return getApplicabilityLevel();
}
@ApplicabilityLevelConstant int level;
Integer boxedLevel = ourOverloadGuard.doPreventingRecursion(myArgumentList, false, new Computable<Integer>() {
@Override

View File

@@ -21,8 +21,10 @@ import com.intellij.psi.codeStyle.JavaCodeStyleManager;
import com.intellij.psi.controlFlow.*;
import com.intellij.psi.impl.PsiImplUtil;
import com.intellij.psi.impl.source.resolve.graphInference.FunctionalInterfaceParameterizationUtil;
import com.intellij.psi.impl.source.resolve.graphInference.InferenceSession;
import com.intellij.psi.impl.source.tree.ChildRole;
import com.intellij.psi.impl.source.tree.JavaElementType;
import com.intellij.psi.infos.MethodCandidateInfo;
import com.intellij.psi.scope.PsiScopeProcessor;
import com.intellij.psi.tree.IElementType;
import com.intellij.psi.util.PsiTreeUtil;
@@ -153,6 +155,17 @@ public class PsiLambdaExpressionImpl extends ExpressionPsiElement implements Psi
}
return false;
}
final PsiElement argsList = PsiTreeUtil.getParentOfType(this, PsiExpressionList.class);
if (MethodCandidateInfo.ourOverloadGuard.currentStack().contains(argsList)) {
if (!hasFormalParameterTypes()) {
return true;
}
final MethodCandidateInfo.CurrentCandidateProperties candidateProperties = MethodCandidateInfo.getCurrentMethod(argsList);
if (candidateProperties != null && !InferenceSession.isPertinentToApplicability(this, candidateProperties.getMethod())) {
return true;
}
}
leftType = FunctionalInterfaceParameterizationUtil.getGroundTargetType(leftType, this);
final PsiClassType.ClassResolveResult resolveResult = PsiUtil.resolveGenericsClassInType(leftType);

View File

@@ -764,14 +764,22 @@ public class PsiMethodReferenceExpressionImpl extends PsiReferenceExpressionBase
return false;
}
final PsiElement argsList = PsiTreeUtil.getParentOfType(this, PsiExpressionList.class);
final boolean isExact = isExact();
if (MethodCandidateInfo.ourOverloadGuard.currentStack().contains(argsList) && isExact) {
final MethodCandidateInfo.CurrentCandidateProperties candidateProperties = MethodCandidateInfo.getCurrentMethod(argsList);
if (candidateProperties != null && !InferenceSession.isPertinentToApplicability(this, candidateProperties.getMethod())) {
return true;
}
}
left = FunctionalInterfaceParameterizationUtil.getGroundTargetType(left);
if (!isPotentiallyCompatible(left)) {
return false;
}
final PsiElement argsList = PsiTreeUtil.getParentOfType(this, PsiExpressionList.class);
if (MethodCandidateInfo.ourOverloadGuard.currentStack().contains(argsList)) {
if (!isExact()) {
if (!isExact) {
return true;
}
}

View File

@@ -351,7 +351,7 @@ public class JavaMethodsConflictResolver implements PsiConflictResolver{
}
private static boolean areTypeParametersAgree(CandidateInfo info) {
return ((MethodCandidateInfo)info).isApplicable();
return ((MethodCandidateInfo)info).getPertinentApplicabilityLevel() != MethodCandidateInfo.ApplicabilityLevel.NOT_APPLICABLE;
}
private static boolean checkParametersNumber(final List<CandidateInfo> conflicts,

View File

@@ -7,7 +7,7 @@ class A<T> {
foo(new A<>("", ""));
bar(new A<>("", ""));
bar(new A<>(get()));
//bar(new A<>(get( ), ""));
bar(new A<>(get( ), ""));
}
void foo(A<String> s) {}

View File

@@ -1,7 +1,7 @@
class Demo {
public void f1() {
f2<error descr="'f2()' in 'Demo' cannot be applied to '(int, <lambda expression>)'">(2, input -> input)</error>;
f2(2, <error descr="Target type of a lambda conversion must be an interface">input -> input</error>);
}
public void f2() {

View File

@@ -0,0 +1,46 @@
import java.util.List;
abstract class StreamMain {
public abstract <T> Iterable<T> concat(final Iterable<? extends T>... iterables);
public abstract <T> Iterable<T> concat(final List<? extends T>... iterables);
public final List<String> errorFixesToShow = null;
public final List<String> inspectionFixesToShow = null;
void foo() {
exists(concat(errorFixesToShow, inspectionFixesToShow), "");
}
public abstract <T> boolean exists(T[] iterable, T t);
public abstract <T> boolean exists(Iterable<T> iterable, T t);
}
abstract class StreamMainComplexSecendArgument {
public abstract <T> Iterable<T> concat(final Iterable<? extends T>... iterables);
public abstract <T> Iterable<T> concat(final List<? extends T>... iterables);
public final List<String> errorFixesToShow = null;
public final List<String> inspectionFixesToShow = null;
void foo() {
Condition<String> condition = new Condition<String>() {
@Override
public boolean value(String s) {
return false;
}
};
exists(concat(errorFixesToShow, inspectionFixesToShow), condition);
}
public abstract <T> boolean exists(T[] iterable, Condition<T> condition);
public abstract <T> boolean exists(Iterable<T> iterable, Condition<T> condition);
interface Condition<T> {
boolean value(T t);
}
}

View File

@@ -47,6 +47,10 @@ public class MostSpecificResolutionTest extends LightDaemonAnalyzerTestCase {
doTest();
}
public void testNestedVarargs() throws Exception {
doTest();
}
private void doTest() {
doTest(true);
}