[java-highlighting] IDEA-324314 Enums must be qualified with switch with compatible types

GitOrigin-RevId: db218b31e81d767fff0c341a00593983522564b1
This commit is contained in:
Mikhail Pyltsin
2023-07-13 12:46:56 +02:00
committed by intellij-monorepo-bot
parent 4f951e7be9
commit 07a6f3f57a
2 changed files with 54 additions and 0 deletions

View File

@@ -0,0 +1,49 @@
import java.util.Optional;
class Main {
interface IT {
}
sealed interface IT2 {
}
enum T implements IT, IT2 {
A, B, C;
public void test2(IT2 t2) {
switch (t2) {
case T.A -> System.out.println("1");
case B -> System.out.println("2");
case T.C -> System.out.println("3");
}
}
}
public static void main(String[] args) {
}
public void test0(IT2 t2) {
switch (t2) {
case T.A -> System.out.println(1);
case T.B -> System.out.println(2);
case T.C -> System.out.println(3);
}
}
public void test1(IT t2) {
switch (<error descr="'switch' statement does not cover all possible input values">t2</error>) {
case T.A -> System.out.println(1);
case T.B -> System.out.println(2);
case T.C -> System.out.println(3);
}
}
public void test2(IT t2) {
switch (t2) {
case T.A -> System.out.println("1");
case <error descr="Cannot resolve symbol 'B'">B</error> -> System.out.println("2");
case T.C -> System.out.println("3");
}
}
}

View File

@@ -70,10 +70,15 @@ public class LightPatternsForSwitchHighlightingTest extends LightJavaCodeInsight
public void testSwitchExhaustivenessForDirectClassesIn21Java() {
IdeaTestUtil.withLevel(getModule(), LanguageLevel.JDK_21, this::doTest);
}
public void testSwitchExhaustivenessWithConcreteSealedClassesIn21Java() {
IdeaTestUtil.withLevel(getModule(), LanguageLevel.JDK_21, this::doTest);
}
public void testSwitchExhaustivenessForEnumsWithSealedClassesIn21Java() {
IdeaTestUtil.withLevel(getModule(), LanguageLevel.JDK_21, this::doTest);
}
public void testSwitchExhaustivenessIn20Java() {
IdeaTestUtil.withLevel(getModule(), LanguageLevel.JDK_20_PREVIEW, this::doTest);
}