[java-highlighting] IDEA-324474 Highlight unreachable statement for exhaustive switch. Tests

GitOrigin-RevId: 97f525a579bd45c6863a6662142f26193e7e2429
This commit is contained in:
Mikhail Pyltsin
2023-07-14 16:14:48 +00:00
committed by intellij-monorepo-bot
parent 2ab3cddf1f
commit afe84f8eed
2 changed files with 51 additions and 0 deletions
@@ -0,0 +1,48 @@
public class Switches {
enum E {
A, B
}
int testReachability(E e) {
switch (e) {
case E d when d == E.A:
return 1;
case A:
return -1;
case B:
return -2;
}
<error descr="Unreachable statement">return</error> 1;
}
sealed interface T {
}
final class T1 implements T {
}
final class T2 implements T {
}
void testReachability2(T i) {
switch (i) {
case T1 f:
throw new RuntimeException();
case T2 s:
throw new RuntimeException();
}
<error descr="Unreachable statement">System.out.println();</error>
}
class Reachability2{
sealed interface T{}
final class T1 implements T{}
int test(T t) {
switch (t) {
case T1 t1: return 2;
}
}
}
}
@@ -114,6 +114,9 @@ public class LightPatternsForSwitchHighlightingTest extends LightJavaCodeInsight
public void testReachability() {
doTest();
}
public void testReachabilityStatement() {
doTest();
}
public void testEffectivelyFinal() {
IdeaTestUtil.withLevel(getModule(), LanguageLevel.JDK_20_PREVIEW, this::doTest);