java 8: allow to cast to intersection types

This commit is contained in:
Anna Kozlova
2014-02-19 09:46:17 +01:00
parent d22feaa947
commit 1b0e87f99e
3 changed files with 20 additions and 0 deletions
@@ -105,6 +105,12 @@ public class TypeConversionUtil {
final int toTypeRank = getTypeRank(toType);
if (!toIsPrimitive) {
if (fromTypeRank == toTypeRank) return true;
if (toType instanceof PsiIntersectionType) {
for (PsiType type : ((PsiIntersectionType)toType).getConjuncts()) {
if (!areTypesConvertible(fromType, type)) return false;
}
return true;
}
// JLS 5.5: A value of a primitive type can be cast to a reference type by boxing conversion(see 5.1.7)
if (!(toType instanceof PsiClassType)) return false;
PsiClass toClass = ((PsiClassType)toType).resolve();
@@ -0,0 +1,10 @@
import java.io.Serializable;
class X {
<T extends Integer & Serializable> void foo(T param) {}
{
foo((Integer & Serializable)0);
}
}
@@ -739,6 +739,10 @@ public class GenericsHighlighting8Test extends LightDaemonAnalyzerTestCase {
doTest();
}
public void testCastToIntersectionType() throws Exception {
doTest();
}
private void doTest() {
doTest(false);
}