diff --git a/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/java/ControlFlowAnalyzer.java b/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/java/ControlFlowAnalyzer.java index c6c94bdc4fb3..bff25635cf48 100644 --- a/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/java/ControlFlowAnalyzer.java +++ b/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/java/ControlFlowAnalyzer.java @@ -979,7 +979,8 @@ public class ControlFlowAnalyzer extends JavaElementVisitor { } selector.accept(this); if (syntheticVar) { - expressionValue = createTempVariable(targetType); + expressionValue = targetType == null ? + myCurrentFlow.createTempVariable(DfType.TOP) : createTempVariable(targetType); addInstruction(new SimpleAssignmentInstruction(null, expressionValue)); } addInstruction(new PopInstruction()); diff --git a/java/java-tests/testData/inspection/dataFlow/fixture/SwitchNoUnreachableBranchesDueToUnresolvedType.java b/java/java-tests/testData/inspection/dataFlow/fixture/SwitchNoUnreachableBranchesDueToUnresolvedType.java new file mode 100644 index 000000000000..bbf313e9bcce --- /dev/null +++ b/java/java-tests/testData/inspection/dataFlow/fixture/SwitchNoUnreachableBranchesDueToUnresolvedType.java @@ -0,0 +1,11 @@ +enum E { + A, B, C; + + int x(E e, String s) { + return switch (d) { + case A -> 1; + case B -> 2; + case C -> 3; + }; + } +} \ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/java/codeInspection/DataFlowInspection21Test.java b/java/java-tests/testSrc/com/intellij/java/codeInspection/DataFlowInspection21Test.java index 71a58f828335..ef879e84a0e2 100644 --- a/java/java-tests/testSrc/com/intellij/java/codeInspection/DataFlowInspection21Test.java +++ b/java/java-tests/testSrc/com/intellij/java/codeInspection/DataFlowInspection21Test.java @@ -184,4 +184,8 @@ public class DataFlowInspection21Test extends DataFlowInspectionTestCase { DataFlowInspectionTest.addJavaxNullabilityAnnotations(myFixture); doTest(); } + + public void testSwitchNoUnreachableBranchesDueToUnresolvedType() { + doTest(); + } } \ No newline at end of file