mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
overload resolution: N parameters of varargs target should be less than N parameters of corresponding interface (IDEA-257526)
GitOrigin-RevId: 811135c478f3f98fa1923f4b58c27d6ca0144939
This commit is contained in:
committed by
intellij-monorepo-bot
parent
118dda6470
commit
7d0ce7b928
+11
-5
@@ -88,18 +88,24 @@ public class PsiMethodReferenceExpressionImpl extends JavaStubPsiElement<Functio
|
||||
final boolean isStatic = ((PsiMethod)element).hasModifierProperty(PsiModifier.STATIC);
|
||||
final int parametersCount = ((PsiMethod)element).getParameterList().getParametersCount();
|
||||
if (qualifierResolveResult.isReferenceTypeQualified() && getReferenceNameElement() instanceof PsiIdentifier) {
|
||||
if (parametersCount == interfaceArity && isStatic) {
|
||||
int offset = isStatic ? 0 : 1;
|
||||
if (parametersCount == interfaceArity - offset) {
|
||||
return true;
|
||||
}
|
||||
if (parametersCount == interfaceArity - 1 && !isStatic) {
|
||||
return true;
|
||||
if (((PsiMethod)element).isVarArgs()) {
|
||||
if (interfaceMethod.isVarArgs()) {
|
||||
return true;
|
||||
}
|
||||
return interfaceArity >= parametersCount + offset - 1;
|
||||
}
|
||||
if (((PsiMethod)element).isVarArgs()) return true;
|
||||
}
|
||||
else if (!isStatic) {
|
||||
if (parametersCount == interfaceArity || ((PsiMethod)element).isVarArgs()) {
|
||||
if (parametersCount == interfaceArity) {
|
||||
return true;
|
||||
}
|
||||
if (((PsiMethod)element).isVarArgs()) {
|
||||
return interfaceMethod.isVarArgs() || interfaceArity >= parametersCount - 1 ;
|
||||
}
|
||||
}
|
||||
} else if (element instanceof PsiClass) {
|
||||
return true;
|
||||
|
||||
+60
@@ -0,0 +1,60 @@
|
||||
|
||||
interface I {
|
||||
void foo(String s, Object... params);
|
||||
}
|
||||
|
||||
class Foo {
|
||||
void n(I i) {}
|
||||
void n(Runnable r) {}
|
||||
void fooBar(String s, Object... params) {}
|
||||
{
|
||||
n(this::fooBar);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class Foo1 {
|
||||
void n(I i) {}
|
||||
void n(Runnable r) {}
|
||||
static void fooBar(String s, Object... params) {}
|
||||
{
|
||||
n(Foo1::fooBar);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
interface I2 {
|
||||
void foo(Foo2 s, Object... params);
|
||||
}
|
||||
|
||||
class Foo2 {
|
||||
void n(I2 i) {}
|
||||
void n(Runnable r) {}
|
||||
void fooBar(Object... params) {}
|
||||
{
|
||||
n(Foo2::fooBar);
|
||||
}
|
||||
|
||||
void fooBar1(Object o, Object... params) {}
|
||||
{
|
||||
n(Foo2::fooBar1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class Foo3 {
|
||||
interface I3 {
|
||||
void foo(Foo3 s, Object... params);
|
||||
}
|
||||
|
||||
interface I4 {
|
||||
void foo(Object params);
|
||||
}
|
||||
|
||||
void n(I3 i) {}
|
||||
void n(I4 r) {}
|
||||
void fooBar(Object o, Object... params) {}
|
||||
{
|
||||
n(Foo3::fooBar);
|
||||
}
|
||||
}
|
||||
+1
@@ -280,6 +280,7 @@ public class OverloadResolutionTest extends LightDaemonAnalyzerTestCase {
|
||||
public void testFixedContainingClassTypeArguments() { doTest(false);}
|
||||
public void testPotentialCompatibilityWithArrayCreation() { doTest(false);}
|
||||
public void testOverloadsWithOneNonCompatible() { doTest(false);}
|
||||
public void testTwoFunctionalInterfacesWithVarargs() { doTest(false);}
|
||||
public void testSecondSearchOverloadsBoxing() {
|
||||
IdeaTestUtil.setTestVersion(JavaSdkVersion.JDK_1_8, getModule(), getTestRootDisposable());
|
||||
String filePath = BASE_PATH + "/" + getTestName(false) + ".java";
|
||||
|
||||
Reference in New Issue
Block a user