mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
cast conversion applicable for wildcard vs type parameter if bounds agree (IDEA-75628)
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
+18
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user