mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
type arguments containment: ensure arrays are contained in type parameters with Serializable, Cloneable or Object bounds (IDEA-165295)
This commit is contained in:
@@ -111,11 +111,11 @@ public class TypesDistinctProver {
|
||||
final PsiClass boundClass2 = classResolveResult2.getElement();
|
||||
|
||||
if (boundClass1 instanceof PsiTypeParameter && level < 2) {
|
||||
if (!distinguishFromTypeParam((PsiTypeParameter)boundClass1, boundClass2, type1)) return false;
|
||||
if (!distinguishFromTypeParam((PsiTypeParameter)boundClass1, boundClass2, type1, type2)) return false;
|
||||
}
|
||||
|
||||
if (boundClass2 instanceof PsiTypeParameter && level < 2) {
|
||||
if (!distinguishFromTypeParam((PsiTypeParameter)boundClass2, boundClass1, type2)) return false;
|
||||
if (!distinguishFromTypeParam((PsiTypeParameter)boundClass2, boundClass1, type2, type1)) return false;
|
||||
}
|
||||
|
||||
if (Comparing.equal(TypeConversionUtil.erasure(type1), TypeConversionUtil.erasure(type2))) {
|
||||
@@ -150,7 +150,10 @@ public class TypesDistinctProver {
|
||||
!InheritanceUtil.isInheritorOrSelf(boundClass2, boundClass1, true));
|
||||
}
|
||||
|
||||
private static boolean distinguishFromTypeParam(PsiTypeParameter typeParam, PsiClass boundClass, PsiType type1) {
|
||||
private static boolean distinguishFromTypeParam(PsiTypeParameter typeParam,
|
||||
PsiClass boundClass,
|
||||
PsiType type1,
|
||||
PsiType type2) {
|
||||
final PsiClassType[] paramBounds = typeParam.getExtendsListTypes();
|
||||
if (paramBounds.length == 0 && type1 instanceof PsiClassType) return false;
|
||||
for (PsiClassType classType : paramBounds) {
|
||||
@@ -160,6 +163,9 @@ public class TypesDistinctProver {
|
||||
InheritanceUtil.isInheritorOrSelf(boundClass, paramBound, true))) {
|
||||
return false;
|
||||
}
|
||||
if (type2 instanceof PsiArrayType && TypeConversionUtil.isAssignable(classType, type2)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
import java.io.Serializable;
|
||||
abstract class Box<<warning descr="Type parameter 'T' is never used">T</warning> extends Serializable> {
|
||||
public static <V extends Serializable> Box<V> get(ByteArrayBox byteArrayBox) {
|
||||
return <warning descr="Unchecked cast: 'ByteArrayBox' to 'Box<V>'">(Box<V>) byteArrayBox</warning>;
|
||||
}
|
||||
}
|
||||
|
||||
final class ByteArrayBox extends Box<byte[]> {}
|
||||
@@ -595,6 +595,10 @@ public class GenericsHighlightingTest extends LightDaemonAnalyzerTestCase {
|
||||
doTest(LanguageLevel.JDK_1_7, JavaSdkVersion.JDK_1_7, false);
|
||||
}
|
||||
|
||||
public void testArrayContainsInTypeParameterWithSerializableBound() throws Exception {
|
||||
doTest(LanguageLevel.JDK_1_7, JavaSdkVersion.JDK_1_7, true);
|
||||
}
|
||||
|
||||
public void testIntersectTypeParameterBounds() throws Exception {
|
||||
doTest(LanguageLevel.JDK_1_7, JavaSdkVersion.JDK_1_7, false);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user