type arguments distinct checker: do not distinguish wildcards with array bounds from arrays with corresponding bounds (IDEA-134944)

This commit is contained in:
Anna Kozlova
2015-11-12 16:14:33 +01:00
parent 3663197387
commit 44f26da2bc
3 changed files with 16 additions and 0 deletions

View File

@@ -259,6 +259,9 @@ public class TypesDistinctProver {
else if (bound instanceof PsiWildcardType) {
final PsiType boundBound = ((PsiWildcardType)bound).getBound();
if (boundBound != null && !boundBound.equals(type)) {
if (boundBound instanceof PsiArrayType && !((PsiWildcardType)bound).isSuper()) {
return proveArrayTypeDistinct(type, boundBound);
}
final PsiClass psiClass = PsiUtil.resolveClassInClassTypeOnly(boundBound);
if (psiClass == null) {
return true;

View File

@@ -0,0 +1,9 @@
class Test {
public static <T> void fooBar(final Class<?> aClass,
final Class<? super Number[]> aSuperClass,
final Class<? extends Number[]> anExtendsClass) {
Class<T[]> klazz = (Class<T[]>) aClass;
klazz = <error descr="Inconvertible types; cannot cast 'java.lang.Class<capture<? super java.lang.Number[]>>' to 'java.lang.Class<T[]>'">(Class<T[]>) aSuperClass</error>;
klazz = (Class<T[]>) anExtendsClass;
}
}

View File

@@ -536,6 +536,10 @@ public class GenericsHighlightingTest extends LightDaemonAnalyzerTestCase {
doTest(LanguageLevel.JDK_1_7, JavaSdkVersion.JDK_1_7, false);
}
public void testProvablyDistinctForWildcardsWithArrayBounds() throws Exception {
doTest(LanguageLevel.JDK_1_7, JavaSdkVersion.JDK_1_7, false);
}
public void testJavaUtilCollections_NoVerify() throws Exception {
PsiClass collectionsClass = getJavaFacade().findClass("java.util.Collections", GlobalSearchScope.moduleWithLibrariesScope(getModule()));
assertNotNull(collectionsClass);