diff --git a/java/java-psi-impl/src/com/intellij/psi/controlFlow/ControlFlowAnalyzer.java b/java/java-psi-impl/src/com/intellij/psi/controlFlow/ControlFlowAnalyzer.java
index 8c6e448ebaa2..5dc2cb59cf6c 100644
--- a/java/java-psi-impl/src/com/intellij/psi/controlFlow/ControlFlowAnalyzer.java
+++ b/java/java-psi-impl/src/com/intellij/psi/controlFlow/ControlFlowAnalyzer.java
@@ -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;
}
diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/switchExpressions/EnhancedSwitchUnreachable.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/switchExpressions/EnhancedSwitchUnreachable.java
index 1273d940ead8..43d0fbd11ab8 100644
--- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/switchExpressions/EnhancedSwitchUnreachable.java
+++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/switchExpressions/EnhancedSwitchUnreachable.java
@@ -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 {
System.out.println();
}
+ void alwaysThrow2(Integer i) {
+ switch (i) {
+ case Integer integer when true:
+ throw new IllegalArgumentException();
+ }
+ System.out.println(42);
+ }
+
void breakFromEndlessLoop() {
EndlessLoop:
for (;;) {
diff --git a/java/java-tests/testSrc/com/intellij/java/codeInsight/daemon/JavaSwitchExpressionsHighlightingTest.kt b/java/java-tests/testSrc/com/intellij/java/codeInsight/daemon/JavaSwitchExpressionsHighlightingTest.kt
index 2c0066cf82a2..4923ff2a8ac0 100644
--- a/java/java-tests/testSrc/com/intellij/java/codeInsight/daemon/JavaSwitchExpressionsHighlightingTest.kt
+++ b/java/java-tests/testSrc/com/intellij/java/codeInsight/daemon/JavaSwitchExpressionsHighlightingTest.kt
@@ -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()