mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-06 03:21:12 +07:00
java switch expressions: infer Object if one of branches has null type (IDEA-241470)
GitOrigin-RevId: 489d3413091cbd1a85348fae0a428e29b287f7e0
This commit is contained in:
committed by
intellij-monorepo-bot
parent
6324dc91a2
commit
8aafb282f3
@@ -92,10 +92,11 @@ public class PsiSwitchExpressionImpl extends PsiSwitchBlockImpl implements PsiSw
|
||||
// to the least upper bound (4.10.4) of the types of the result expressions.
|
||||
PsiType leastUpperBound = PsiType.NULL;
|
||||
for (PsiType type : resultTypes) {
|
||||
if (TypeConversionUtil.isNullType(type)) return PsiType.getJavaLangObject(getManager(), getResolveScope());
|
||||
if (TypeConversionUtil.isPrimitiveAndNotNull(type)) {
|
||||
type = ((PsiPrimitiveType)type).getBoxedType(this);
|
||||
}
|
||||
if (leastUpperBound == PsiType.NULL) {
|
||||
if (TypeConversionUtil.isNullType(leastUpperBound)) {
|
||||
leastUpperBound = type;
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -116,4 +116,12 @@ class MyTest {
|
||||
|
||||
System.out.println(c.getCanonicalName());
|
||||
}
|
||||
|
||||
static void testNull(int i) {
|
||||
var v = switch(i) {
|
||||
case 1 -> "abcd";
|
||||
default -> null;
|
||||
};
|
||||
System.out.println(v.<error descr="Cannot resolve method 'substring' in 'Object'">substring</error>(1));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user