[java] switch expressions: allow null label with any non-primitive type (IDEA-282339)

GitOrigin-RevId: d6438daeba88dc37ec34509e331394a87cf1cd8d
This commit is contained in:
Anna Kozlova
2021-11-14 18:48:39 +00:00
committed by intellij-monorepo-bot
parent c58089fa4d
commit 2aa9ed116e
2 changed files with 13 additions and 1 deletions
@@ -452,7 +452,7 @@ public class SwitchBlockHighlightingModel {
private HighlightInfo checkLabelAndSelectorCompatibility(@NotNull PsiCaseLabelElement label) {
if (label instanceof PsiDefaultCaseLabelElement) return null;
if (isNullType(label)) {
if (!(mySelectorType instanceof PsiClassType) && !isNullType(mySelector)) {
if (mySelectorType instanceof PsiPrimitiveType && !isNullType(mySelector)) {
return createError(label, JavaErrorBundle.message("incompatible.switch.null.type", "null",
JavaHighlightUtil.formatType(mySelectorType)));
}
@@ -183,6 +183,18 @@ class Main {
case ((((<error descr="'java.util.List<capture<? extends java.lang.Number>>' cannot be safely cast to 'java.util.List<java.lang.Integer>'">List<Integer> l</error>)) && Math.random() > 0.5)):
break;
}
switch (list1.get(0)) {
case null: {}
default: {}
}
switch (new int[0]) {
case null: {}
default: {}
}
switch (list2) {
case List<? extends Number> l:
break;