mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-05-06 05:10:22 +07:00
method references: compare number of arguments for non-vararg applicability only (IDEA-132708)
This commit is contained in:
@@ -297,13 +297,12 @@ public class MethodReferenceResolver implements ResolveCache.PolyVariantContextR
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean nonComparable(@NotNull CandidateInfo method, @NotNull CandidateInfo conflict) {
|
||||
protected boolean nonComparable(@NotNull CandidateInfo method, @NotNull CandidateInfo conflict, boolean fixedArity) {
|
||||
if (method == conflict) return true;
|
||||
PsiElement psiElement = method.getElement();
|
||||
PsiElement conflictElement = conflict.getElement();
|
||||
if (psiElement instanceof PsiMethod && conflictElement instanceof PsiMethod) {
|
||||
if (((PsiMethod)psiElement).getParameterList().getParametersCount() !=
|
||||
((PsiMethod)conflictElement).getParameterList().getParametersCount()) {
|
||||
if (fixedArity && ((PsiMethod)psiElement).getParameterList().getParametersCount() != ((PsiMethod)conflictElement).getParameterList().getParametersCount()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -179,7 +179,7 @@ public class JavaMethodsConflictResolver implements PsiConflictResolver{
|
||||
for (int j = 0; j < i; j++) {
|
||||
ProgressManager.checkCanceled();
|
||||
final CandidateInfo conflict = newConflictsArray[j];
|
||||
if (nonComparable(method, conflict)) continue;
|
||||
if (nonComparable(method, conflict, applicabilityLevel == MethodCandidateInfo.ApplicabilityLevel.FIXED_ARITY)) continue;
|
||||
switch (isMoreSpecific((MethodCandidateInfo)method, (MethodCandidateInfo)conflict, applicabilityLevel, languageLevel)) {
|
||||
case FIRST:
|
||||
conflicts.remove(conflict);
|
||||
@@ -195,7 +195,7 @@ public class JavaMethodsConflictResolver implements PsiConflictResolver{
|
||||
}
|
||||
}
|
||||
|
||||
protected boolean nonComparable(@NotNull CandidateInfo method, @NotNull CandidateInfo conflict) {
|
||||
protected boolean nonComparable(@NotNull CandidateInfo method, @NotNull CandidateInfo conflict, boolean fixedArity) {
|
||||
assert method != conflict;
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
import java.util.function.Consumer;
|
||||
|
||||
class Test {
|
||||
public static void main(String[] args) {
|
||||
Consumer<String> ref = Test::method;
|
||||
System.out.println(ref);
|
||||
}
|
||||
|
||||
static void method(String arg, Object... args) {
|
||||
System.out.println(arg);
|
||||
System.out.println(args);
|
||||
}
|
||||
static void method(Object... args) {
|
||||
System.out.println(args);
|
||||
}
|
||||
}
|
||||
@@ -111,6 +111,10 @@ public class MostSpecificResolutionTest extends LightDaemonAnalyzerTestCase {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testVarargsSpecificsDuringMethodReferenceResolve() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
private void doTest() {
|
||||
doTest(true);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user