mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-19 13:02:30 +07:00
[java-highlighting] 'switch' expression does not cover all possible input values: false positive on reference types
IDEA-309593 GitOrigin-RevId: f869a8a1a98fd7789f5d07290797205205733899
This commit is contained in:
committed by
intellij-monorepo-bot
parent
bbb4375761
commit
3f34cfe3ea
@@ -244,11 +244,11 @@ public class SwitchBlockHighlightingModel {
|
||||
// todo replace with needToCheckCompleteness
|
||||
if (!holder.hasErrorResults() && myBlock instanceof PsiSwitchExpression && !hasDefaultCase) {
|
||||
PsiClass selectorClass = PsiUtil.resolveClassInClassTypeOnly(mySelectorType);
|
||||
if (selectorClass == null) {
|
||||
holder.add(createCompletenessInfoForSwitch(!values.keySet().isEmpty()).create());
|
||||
if (selectorClass != null && selectorClass.isEnum()) {
|
||||
checkEnumCompleteness(selectorClass, ContainerUtil.map(values.keySet(), String::valueOf), holder);
|
||||
}
|
||||
else {
|
||||
checkEnumCompleteness(selectorClass, ContainerUtil.map(values.keySet(), String::valueOf), holder);
|
||||
holder.add(createCompletenessInfoForSwitch(!values.keySet().isEmpty()).create());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ import java.util.Random;
|
||||
class SwitchExpressions {
|
||||
enum E { E1, E2 }
|
||||
|
||||
void m() {
|
||||
void m(String s, Integer i) {
|
||||
System.out.println(switch (new Random().nextInt()) {
|
||||
default -> "whatever";
|
||||
});
|
||||
@@ -45,6 +45,14 @@ class SwitchExpressions {
|
||||
System.out.println(switch (<error descr="'switch' expression does not cover all possible input values">E.valueOf("E1")</error>) {
|
||||
case E1 -> 1;
|
||||
});
|
||||
System.out.println(switch (<error descr="'switch' expression does not cover all possible input values">s</error>) {
|
||||
case "blah blah blah" -> 1;
|
||||
});
|
||||
System.out.println(switch (<error descr="'switch' expression does not cover all possible input values">i</error>) {
|
||||
case 42 -> 1;
|
||||
});
|
||||
System.out.println(switch (<error descr="'switch' expression does not have any case clauses">s</error>) {});
|
||||
System.out.println(switch (<error descr="'switch' expression does not have any case clauses">i</error>) {});
|
||||
System.out.println(switch (E.valueOf("E1")) {
|
||||
case E1 -> 1;
|
||||
case E2 -> 2;
|
||||
|
||||
Reference in New Issue
Block a user