mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
conditional: treat nulls separately and accept them as numeric/boolean branches (IDEA-157025)
This commit is contained in:
+7
-3
@@ -160,7 +160,7 @@ public class PsiPolyExpressionUtil {
|
||||
}
|
||||
|
||||
private enum ConditionalKind {
|
||||
BOOLEAN, NUMERIC
|
||||
BOOLEAN, NUMERIC, NULL
|
||||
}
|
||||
|
||||
private static ConditionalKind isBooleanOrNumeric(PsiExpression expr) {
|
||||
@@ -192,14 +192,18 @@ public class PsiPolyExpressionUtil {
|
||||
final PsiExpression elseExpression = ((PsiConditionalExpression)expr).getElseExpression();
|
||||
final ConditionalKind thenKind = isBooleanOrNumeric(thenExpression);
|
||||
final ConditionalKind elseKind = isBooleanOrNumeric(elseExpression);
|
||||
if (thenKind == elseKind || elseKind == null) return thenKind;
|
||||
if (thenKind == null) return elseKind;
|
||||
if (thenKind == elseKind || elseKind == ConditionalKind.NULL) return thenKind;
|
||||
if (thenKind == ConditionalKind.NULL) return elseKind;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static ConditionalKind isBooleanOrNumericType(PsiType type) {
|
||||
if (type == PsiType.NULL) {
|
||||
return ConditionalKind.NULL;
|
||||
}
|
||||
|
||||
final PsiClass psiClass = PsiUtil.resolveClassInClassTypeOnly(type);
|
||||
if (TypeConversionUtil.isNumericType(type)) return ConditionalKind.NUMERIC;
|
||||
if (TypeConversionUtil.isBooleanType(type)) return ConditionalKind.BOOLEAN;
|
||||
|
||||
+5
@@ -6,6 +6,11 @@ class Conditional {
|
||||
int a2 = b ? null : 1;
|
||||
int a3 = b ? null : f1();
|
||||
int a4 = b ? null : f2();
|
||||
Long someNum = b ? getNum(5L) : <error descr="Incompatible types. Found: 'int', required: 'java.lang.Long'">0</error>;
|
||||
}
|
||||
|
||||
private static <T> T getNum(T num) {
|
||||
return num;
|
||||
}
|
||||
|
||||
private static <T> T f() {
|
||||
|
||||
Reference in New Issue
Block a user