mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
java 8: allow to cast to intersection types
This commit is contained in:
@@ -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();
|
||||
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
import java.io.Serializable;
|
||||
|
||||
class X {
|
||||
|
||||
<T extends Integer & Serializable> void foo(T param) {}
|
||||
|
||||
{
|
||||
foo((Integer & Serializable)0);
|
||||
}
|
||||
}
|
||||
+4
@@ -739,6 +739,10 @@ public class GenericsHighlighting8Test extends LightDaemonAnalyzerTestCase {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testCastToIntersectionType() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
private void doTest() {
|
||||
doTest(false);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user