inherit with different parameterization: fix for raw types (IDEA-186271)

This commit is contained in:
Anna.Kozlova
2018-02-07 18:36:34 +01:00
parent d536d50a3c
commit 55d26d0c27
3 changed files with 18 additions and 1 deletions
@@ -354,7 +354,9 @@ public class GenericsHighlightUtil {
final PsiClass superClass = result.getElement();
if (superClass == null || visited.contains(superClass)) continue;
PsiSubstitutor superTypeSubstitutor = result.getSubstitutor();
superTypeSubstitutor = MethodSignatureUtil.combineSubstitutors(superTypeSubstitutor, derivedSubstitutor);
//JLS 4.8 The superclasses (respectively, superinterfaces) of a raw type are the erasures of the superclasses (superinterfaces) of any of the parameterizations of the generic type.
superTypeSubstitutor = PsiUtil.isRawSubstitutor(aClass, derivedSubstitutor) ? JavaPsiFacade.getElementFactory(aClass.getProject()).createRawSubstitutor(superClass)
: MethodSignatureUtil.combineSubstitutors(superTypeSubstitutor, derivedSubstitutor);
final PsiSubstitutor inheritedSubstitutor = inheritedClasses.get(superClass);
if (inheritedSubstitutor != null) {
@@ -0,0 +1,14 @@
interface A<T> {}
interface X1<T> extends A<String> {}
interface Y1<T> extends A<Integer> {}
interface Z1 extends X1, Y1 { }
interface X2 extends A<String> {}
interface Y2<T> extends A<Integer> {}
<error descr="'A' cannot be inherited with different type arguments: 'java.lang.String' and 'null'">interface Z2 extends X2, Y2</error> { }
interface X3 extends A<String> {}
interface Y3 extends A<Integer> {}
<error descr="'A' cannot be inherited with different type arguments: 'java.lang.String' and 'java.lang.Integer'">interface Z3 extends X3, Y3</error> { }
@@ -430,4 +430,5 @@ public class GenericsHighlightingTest extends LightDaemonAnalyzerTestCase {
public void testRecursiveParamBoundsWhenSuperSubstitution() { doTest6(false); }
public void testCaptureForBoundCheck() { doTest6(false); }
public void testGetClassInAnonymous() { doTest6(false); }
public void testInheritFromDifferentParameterizations() { doTest6(false); }
}