mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Java: report primitive patterns in switch after case null branch correctly (IDEA-374619)
GitOrigin-RevId: 3afe71cd1d81188830b1cc332689f42c33e8da8b
This commit is contained in:
committed by
intellij-monorepo-bot
parent
aa7f2804fb
commit
17abd817b0
+3
-6
@@ -294,13 +294,10 @@ final class SwitchChecker {
|
||||
if (labelElementList == null) continue;
|
||||
for (PsiCaseLabelElement label : labelElementList.getElements()) {
|
||||
if (!(label instanceof PsiParenthesizedExpression) && ExpressionUtil.isNullLiteral(label)) {
|
||||
if (selectorType instanceof PsiPrimitiveType) {
|
||||
if (!PsiTypes.nullType().equals(selectorType)) {
|
||||
myVisitor.report(JavaErrorKinds.SWITCH_NULL_TYPE_INCOMPATIBLE.create(label, selectorType));
|
||||
return;
|
||||
}
|
||||
if (selectorType instanceof PsiPrimitiveType && !PsiTypes.nullType().equals(selectorType)) {
|
||||
myVisitor.report(JavaErrorKinds.SWITCH_NULL_TYPE_INCOMPATIBLE.create(label, selectorType));
|
||||
}
|
||||
return;
|
||||
continue;
|
||||
}
|
||||
if (label instanceof PsiExpression expr) {
|
||||
if (selectorType.equals(PsiTypes.nullType())) {
|
||||
|
||||
+16
@@ -27,6 +27,22 @@ class X {
|
||||
};
|
||||
}
|
||||
|
||||
boolean method(Long l) {
|
||||
return switch (l) {
|
||||
case null -> false;
|
||||
case <error descr="Primitive types in patterns, instanceof and switch are not supported at language level '21'">long ll</error> when (ll & 1) > 0 -> true;
|
||||
default -> false;
|
||||
};
|
||||
}
|
||||
|
||||
boolean method(int l) {
|
||||
return switch (l) {
|
||||
case <error descr="'null' cannot be converted to 'int'">null</error> -> false;
|
||||
case <error descr="Primitive types in patterns, instanceof and switch are not supported at language level '21'">long ll</error> when (ll & 1) > 0 -> true;
|
||||
default -> false;
|
||||
};
|
||||
}
|
||||
|
||||
void switchTest3(<error descr="Cannot resolve symbol 'Point'">Point</error><? extends String> point1, <error descr="Cannot resolve symbol 'Point'">Point</error><? super String> point2) {
|
||||
switch (point1) {
|
||||
case <error descr="Cannot resolve symbol 'Point'">Point</error><?>() -> {}
|
||||
|
||||
Reference in New Issue
Block a user