[java-highlighting] IDEA-313993 unreachable statement: false negative

GitOrigin-RevId: 396da7635b4bee1c921444c2b23f89f8c67e5895
This commit is contained in:
Andrey Cherkasov
2023-02-24 13:26:51 +00:00
committed by intellij-monorepo-bot
parent 84afde6440
commit 5e839de419
3 changed files with 13 additions and 3 deletions
@@ -979,7 +979,7 @@ final class ControlFlowAnalyzer extends JavaElementVisitor {
if (labelElementList != null) {
for (PsiCaseLabelElement element : labelElementList.getElements()) {
if (element instanceof PsiDefaultCaseLabelElement ||
element instanceof PsiPattern && exprType != null && JavaPsiPatternUtil.isUnconditionalForType(element, exprType)) {
exprType != null && JavaPsiPatternUtil.isUnconditionalForType(element, exprType)) {
needToCreateDefault = true;
break;
}
@@ -1,5 +1,5 @@
class C {
void alwaysThrow(String s) {
void alwaysThrow1(String s) {
switch (s) {
case "a" -> throw new IllegalArgumentException();
default -> throw new IllegalStateException();
@@ -7,6 +7,14 @@ class C {
<error descr="Unreachable statement">System.out.println();</error>
}
void alwaysThrow2(Integer i) {
switch (i) {
case Integer integer when true:
throw new IllegalArgumentException();
}
<error descr="Unreachable statement">System.out.println(42);</error>
}
void breakFromEndlessLoop() {
EndlessLoop:
for (;;) {
@@ -3,6 +3,8 @@ package com.intellij.java.codeInsight.daemon
import com.intellij.JavaTestUtil
import com.intellij.codeInspection.redundantCast.RedundantCastInspection
import com.intellij.pom.java.LanguageLevel
import com.intellij.testFramework.IdeaTestUtil
import com.intellij.testFramework.fixtures.LightJavaCodeInsightFixtureTestCase
class JavaSwitchExpressionsHighlightingTest : LightJavaCodeInsightFixtureTestCase() {
@@ -16,7 +18,7 @@ class JavaSwitchExpressionsHighlightingTest : LightJavaCodeInsightFixtureTestCas
fun testSwitchNumericPromotion() = doTest()
fun testSimpleInferenceCases() = doTest()
fun testEnhancedSwitchDefinitelyAssigned() = doTest()
fun testEnhancedSwitchUnreachable() = doTest()
fun testEnhancedSwitchUnreachable() = IdeaTestUtil.withLevel(module, LanguageLevel.JDK_20_PREVIEW) { doTest() }
fun testSwitchExpressionHasResult() = doTest()
fun testYieldStatements() = doTest()
fun testAssignToFinalInSwitchExpression() = doTest()