captured wildcards: fix casting to arrays (IDEA-150124)

This commit is contained in:
Anna Kozlova
2016-01-07 20:14:48 +01:00
parent c16e402bed
commit d0102e37cb
3 changed files with 40 additions and 0 deletions
@@ -177,6 +177,9 @@ public class TypeConversionUtil {
return true;
}
}
if (fromType instanceof PsiCapturedWildcardType) {
return isNarrowingReferenceConversionAllowed(((PsiCapturedWildcardType)fromType).getUpperBound(), toType);
}
return isAssignable(fromType, toType);
}
if (fromType instanceof PsiArrayType) {
@@ -0,0 +1,33 @@
import java.util.List;
class Test2 {
private static void test(List<?> list, F<?> f, F<? super Runnable> fs, F<? extends Test2> fe) {
boolean isObjectArray = list.get(0) instanceof Object[];
boolean isObjectArray1 = <error descr="Inconvertible types; cannot cast 'capture<?>' to 'java.lang.Object[]'">f.get() instanceof Object[]</error>;
boolean isObjectArrays = <error descr="Inconvertible types; cannot cast 'capture<? super java.lang.Runnable>' to 'java.lang.Object[]'">fs.get() instanceof Object[]</error>;
boolean isObjectArraye = <error descr="Inconvertible types; cannot cast 'capture<? extends Test2>' to 'java.lang.Object[]'">fe.get() instanceof Object[]</error>;
}
private static void test(G<?> g,
G<? super Cloneable> gs,
G<? extends Test2> ge,
G<? extends Test2[]> gea) {
boolean isObjectArray1 = g.get() instanceof Object[];
boolean isObjectArrays = gs.get() instanceof Object[];
boolean isObjectArraye = <error descr="Inconvertible types; cannot cast 'capture<? extends Test2>' to 'java.lang.Object[]'">ge.get() instanceof Object[]</error>;
boolean isObjectArrayea = gea.get() instanceof Object[];
}
class F<T extends Runnable> {
public T get() {
return null;
}
}
class G<T extends Cloneable> {
public T get() {
return null;
}
}
}
@@ -946,4 +946,8 @@ public class GenericsHighlighting8Test extends LightDaemonAnalyzerTestCase {
public void testCastingCapturedWildcardToPrimitive() throws Exception {
doTest();
}
public void testCastingCapturedWildcardToArray() throws Exception {
doTest();
}
}