mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[java-highlighting] IDEA-324474 Highlight unreachable statement for exhaustive switch. Tests
GitOrigin-RevId: 97f525a579bd45c6863a6662142f26193e7e2429
This commit is contained in:
committed by
intellij-monorepo-bot
parent
2ab3cddf1f
commit
afe84f8eed
+48
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+3
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user