generics: from same signature methods prefer methods without wildcards (IDEA-90802)

This commit is contained in:
anna
2012-10-31 14:23:18 +01:00
parent 06e746448c
commit f743e7ae8c
3 changed files with 34 additions and 3 deletions

View File

@@ -282,9 +282,15 @@ public class JavaMethodsConflictResolver implements PsiConflictResolver{
}
if (currentClass != null && InheritanceUtil.isInheritorOrSelf(currentClass, class1, true) && InheritanceUtil.isInheritorOrSelf(currentClass, existingClass, true)) {
if (MethodSignatureUtil.areSignaturesEqual(existingMethod.getSignature(TypeConversionUtil.getSuperClassSubstitutor(existingClass, currentClass, PsiSubstitutor.EMPTY)),
method.getSignature(TypeConversionUtil.getSuperClassSubstitutor(class1, currentClass, PsiSubstitutor.EMPTY)))) {
conflicts.remove(i);
final PsiSubstitutor eSubstitutor = TypeConversionUtil.getSuperClassSubstitutor(existingClass, currentClass, PsiSubstitutor.EMPTY);
final PsiSubstitutor cSubstitutor = TypeConversionUtil.getSuperClassSubstitutor(class1, currentClass, PsiSubstitutor.EMPTY);
if (MethodSignatureUtil.areSignaturesEqual(existingMethod.getSignature(eSubstitutor), method.getSignature(cSubstitutor))) {
final PsiType returnType = cSubstitutor.substitute(method.getReturnType());
if (PsiUtil.captureToplevelWildcards(returnType, method).equals(returnType)) {
conflicts.remove(existing);
} else {
conflicts.remove(i);
}
i--;
break;
}

View File

@@ -0,0 +1,24 @@
import java.util.*;
interface VcsRoot {
}
interface SVcsRoot extends VcsRoot {
}
interface A {
List<? extends VcsRoot> getVcsRoots();
}
interface B {
List<SVcsRoot> getVcsRoots();
}
interface F1 extends A, B {
}
class G {
void f(F1 o) {
SVcsRoot r = o.getVcsRoots().get(0);
}
}

View File

@@ -180,6 +180,7 @@ public class GenericsHighlightingTest extends LightDaemonAnalyzerTestCase {
public void testIDEA57310() throws Exception { doTest(false); }
public void testIDEA57311() throws Exception { doTest(false); }
public void testIDEA57309() throws Exception { doTest(false); }
public void testIDEA90802() throws Exception { doTest(false); }
public void testInconvertibleTypes() throws Exception { doTest(false); }
public void testIncompatibleReturnType() throws Exception { doTest(false); }
public void testContinueInferenceAfterFirstRawResult() throws Exception { doTest(false); }