overload resolution: adapt return types before comparing (IDEA-177065)

This commit is contained in:
Anna.Kozlova
2017-08-07 18:22:46 +02:00
parent f1fd8e4bc7
commit dec0d16597
3 changed files with 28 additions and 3 deletions

View File

@@ -560,9 +560,9 @@ public class JavaMethodsConflictResolver implements PsiConflictResolver{
return Specifics.FIRST;
}
if (abstract1 && abstract2 && MethodSignatureUtil.areOverrideEquivalent(method1, method2)) {
final PsiType returnType1 = method1.getReturnType();
final PsiType returnType2 = method2.getReturnType();
if (abstract1 && MethodSignatureUtil.areOverrideEquivalent(method1, method2)) { // abstract1 && abstract2
final PsiType returnType1 = siteSubstitutor1.substitute(method1.getReturnType());
final PsiType returnType2 = siteSubstitutor2.substitute(method2.getReturnType());
if (returnType1 != null && returnType2 != null && returnType1.isAssignableFrom(returnType2)) {
return Specifics.SECOND;
}

View File

@@ -0,0 +1,23 @@
import java.util.Collections;
import java.util.List;
interface A<T, ID> {
Iterable<T> findAll(Iterable<ID> ids);
}
interface B<T, ID> {
List<T> findAll(Iterable<ID> ids);
}
interface C<T> extends B<T, Integer>, A<T, Integer> {}
interface D extends C<String> {}
class Test {
public void foo(D d, C<String> c) {
List<Integer> ids = Collections.emptyList();
List<String> strings = d.findAll(ids);
List<String> strings1 = c.findAll(ids);
}
}

View File

@@ -260,6 +260,8 @@ public class OverloadResolutionTest extends LightDaemonAnalyzerTestCase {
doTest(false);
}
public void testAdaptReturnTypesOfSiblingMethods() { doTest(false);}
private void doTest() {
doTest(true);
}