cast conversion applicable for wildcard vs type parameter if bounds agree (IDEA-75628)

This commit is contained in:
Anna Kozlova
2015-02-20 19:46:49 +01:00
parent 66e83ed9ae
commit a7efd33b2b
3 changed files with 29 additions and 1 deletions
@@ -262,7 +262,13 @@ public class TypesDistinctProver {
final PsiType boundBound = ((PsiWildcardType)bound).getBound();
if (boundBound != null && !boundBound.equals(type)) {
final PsiClass psiClass = PsiUtil.resolveClassInClassTypeOnly(boundBound);
return psiClass == null || !(((PsiWildcardType)bound).isExtends() && possibleClasses.contains(psiClass));
if (psiClass == null) {
return true;
}
if (psiClass instanceof PsiTypeParameter) {
return try2ProveTypeParameterDistinct(type, psiClass);
}
return !(((PsiWildcardType)bound).isExtends() && possibleClasses.contains(psiClass));
}
return false;
}
@@ -0,0 +1,18 @@
abstract class Test {
interface Selection<A> {}
interface CriteriaQuery<T> {
void select(Selection<? extends T> selection);
}
private <N> void foo(CriteriaQuery<N> criteria, Selection<String[]> array) {
criteria.select((Selection<? extends N>)array);
}
private <N extends Integer> void foo1(CriteriaQuery<N> criteria, Selection<String[]> array) {
criteria.select(<error descr="Inconvertible types; cannot cast 'Test.Selection<java.lang.String[]>' to 'Test.Selection<? extends N>'">(Selection<? extends N>)array</error>);
}
private <N extends Integer> void foo2(CriteriaQuery<N> criteria, Selection<Object> array) {
criteria.select(<error descr="Inconvertible types; cannot cast 'Test.Selection<java.lang.Object>' to 'Test.Selection<? extends N>'">(Selection<? extends N>)array</error>);
}
}
@@ -459,6 +459,10 @@ public class GenericsHighlightingTest extends LightDaemonAnalyzerTestCase {
doTest(LanguageLevel.JDK_1_7, JavaSdkVersion.JDK_1_7, false);
}
public void testTypeDistinctProverForWildcardAndTypeParameter() 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);