mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
unchecked casts: ignore extends wildcards with the same bound as corresponding type parameter bound (IDEA-71629)
This commit is contained in:
+15
-1
@@ -55,4 +55,18 @@ class M {
|
||||
public static <T extends K> L f(T t) {
|
||||
return (L) t; //this should NOT generate unchecked cast
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class UncheckedCastFalsePositive {
|
||||
|
||||
public static void method(Object something) {
|
||||
if (something instanceof NumberList) {
|
||||
NumberList<? extends Number> <warning descr="Variable 'numberList' is never used">numberList</warning> = (NumberList<? extends Number>) something;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class NumberList<E extends Number> extends ArrayList<E> {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -119,7 +119,7 @@ public abstract class PsiClassType extends PsiType {
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the class type has any parameters which are not unbounded wildcards
|
||||
* Checks if the class type has any parameters which are not unbounded wildcards (and not extends-wildcard with the same bound as corresponding type parameter bound)
|
||||
* and do not have substituted arguments.
|
||||
*
|
||||
* @return true if the class type has nontrivial non-substituted parameters, false otherwise
|
||||
@@ -131,7 +131,17 @@ public abstract class PsiClassType extends PsiType {
|
||||
for (PsiTypeParameter parameter : PsiUtil.typeParametersIterable(aClass)) {
|
||||
PsiType type = resolveResult.getSubstitutor().substitute(parameter);
|
||||
if (type != null) {
|
||||
if (!(type instanceof PsiWildcardType) || ((PsiWildcardType)type).getBound() != null) {
|
||||
if (!(type instanceof PsiWildcardType)) {
|
||||
return true;
|
||||
}
|
||||
final PsiType bound = ((PsiWildcardType)type).getBound();
|
||||
if (bound != null) {
|
||||
if (((PsiWildcardType)type).isExtends()) {
|
||||
final PsiClass superClass = parameter.getSuperClass();
|
||||
if (superClass != null && PsiUtil.resolveClassInType(bound) == superClass) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user