mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
unchecked cast warning: missed captured wildcards (IDEA-158080); reifiable captured wildcard type
This commit is contained in:
+7
@@ -74,6 +74,10 @@ public class JavaGenericsUtil {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (type instanceof PsiCapturedWildcardType) {
|
||||
return isReifiableType(((PsiCapturedWildcardType)type).getUpperBound());
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -127,6 +131,9 @@ public class JavaGenericsUtil {
|
||||
if (castType instanceof PsiClassType) {
|
||||
final PsiClassType castClassType = (PsiClassType)castType;
|
||||
operandType = operandType.getDeepComponentType();
|
||||
if (operandType instanceof PsiCapturedWildcardType) {
|
||||
operandType = ((PsiCapturedWildcardType)operandType).getUpperBound();
|
||||
}
|
||||
|
||||
if (!(operandType instanceof PsiClassType)) return false;
|
||||
final PsiClassType operandClassType = (PsiClassType)operandType;
|
||||
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
import java.util.List;
|
||||
|
||||
class Test {
|
||||
public void bar(List<?> list) {
|
||||
foo(list.get(0));
|
||||
}
|
||||
|
||||
private final <K>void foo(K... <warning descr="Parameter 'k' is never used">k</warning>) {}
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
import java.util.List;
|
||||
|
||||
class Test {
|
||||
public <A> void foo(List<?> list, List<? extends Object> list2) {
|
||||
Comparable<A> <warning descr="Variable 'c1' is never used">c1</warning> = <warning descr="Unchecked cast: 'capture<?>' to 'java.lang.Comparable<A>'">(Comparable<A>)list.get(0)</warning>;
|
||||
Comparable<A> <warning descr="Variable 'c2' is never used">c2</warning> = <warning descr="Unchecked cast: 'capture<? extends java.lang.Object>' to 'java.lang.Comparable<A>'">(Comparable<A>)list2.get(0)</warning>;
|
||||
}
|
||||
}
|
||||
+8
@@ -998,4 +998,12 @@ public class GenericsHighlighting8Test extends LightDaemonAnalyzerTestCase {
|
||||
public void testErasureOfReturnTypeOfNonGenericMethod() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testUncheckedCastWithCapturedWildcards() throws Exception {
|
||||
doTest(true);
|
||||
}
|
||||
|
||||
public void testReifiableCapturedWildcards() throws Exception {
|
||||
doTest(true);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user