mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
method references overload resolution: skip static methods of interfaces called on inheritor (IDEA-209920)
GitOrigin-RevId: 9e7889def32913679fa867f9dd2a80f8d187964e
This commit is contained in:
committed by
intellij-monorepo-bot
parent
d3928de54b
commit
7a03a2be5c
+10
@@ -289,6 +289,16 @@ public class MethodReferenceResolver implements ResolveCache.PolyVariantContextR
|
||||
|
||||
if ((varargs || functionalInterfaceParamTypes.length == parameterTypes.length) &&
|
||||
isCorrectAssignment(parameterTypes, functionalInterfaceParamTypes, interfaceMethod, varargs, referenceExpression, conflict, 0)) {
|
||||
//reject static interface methods called on something else but interface class
|
||||
if (psiMethod.hasModifierProperty(PsiModifier.STATIC)) {
|
||||
PsiClass containingClass = psiMethod.getContainingClass();
|
||||
if (containingClass != null && containingClass.isInterface()) {
|
||||
final PsiClass qualifierClass = PsiMethodReferenceUtil.getQualifierResolveResult(referenceExpression).getContainingClass();
|
||||
if (!containingClass.getManager().areElementsEquivalent(qualifierClass, containingClass)) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
class Main {
|
||||
|
||||
void m(B b) {
|
||||
Function<A<String>, String> f1 = A<String>::getName;
|
||||
Function<A<String>, String> f10 = A::getName;
|
||||
Function<B, String> f2 = B::getName;
|
||||
Function<B, String> f3 = b::<error descr="Cannot resolve method 'getName'">getName</error>;
|
||||
}
|
||||
}
|
||||
|
||||
interface I {
|
||||
String getName();
|
||||
|
||||
static String getName(final I i) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
class A<T> implements I {
|
||||
@Override
|
||||
public String getName() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
class B implements I {
|
||||
@Override
|
||||
public String getName() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
+1
@@ -271,6 +271,7 @@ public class OverloadResolutionTest extends LightDaemonAnalyzerTestCase {
|
||||
public void testOverriddenMethodWithOtherRawSignature() { doTest(false);}
|
||||
|
||||
public void testMoreSpecificForRawSignatureOnStaticProblem() { doTest(false);}
|
||||
public void testSkipStaticInterfaceMethodCalledOnInheritorForMethodRefConflictResolving() { doTest(false);}
|
||||
|
||||
public void testUnqualifiedStaticInterfaceMethodCallsOnInnerClasses() { doTest(false);}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user