Skip to content

Commit 432a508

Browse files
A switch expression that matches no label does not reach the code after it
Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 02cb508 commit 432a508

2 files changed

Lines changed: 18 additions & 1 deletion

File tree

‎liquidjava-example/src/main/java/testSuite/CorrectEnumUsage.java‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,4 +76,20 @@ public static boolean captureExpression(Mode mode) {
7676
default -> false;
7777
};
7878
}
79+
80+
// A switch expression that matches no label throws: it does not reach the code after it
81+
public static void captureOnThread(Thread.State state) {
82+
CorrectEnumUsage st = new CorrectEnumUsage();
83+
boolean running = switch (state) {
84+
case NEW, RUNNABLE, BLOCKED -> {
85+
st.setMode(Mode.Photo);
86+
yield true;
87+
}
88+
case WAITING, TIMED_WAITING, TERMINATED -> {
89+
st.setMode(Mode.Photo);
90+
yield false;
91+
}
92+
};
93+
st.takePhoto();
94+
}
7995
}

‎liquidjava-verifier/src/main/java/liquidjava/processor/refinement_checker/RefinementTypeChecker.java‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -668,8 +668,9 @@ Predicate matches(String selectorName) {
668668
*/
669669
private boolean visitCases(CtAbstractSwitch<?> switchElement, List<CtCase<?>> cases, List<CaseEntry> entries,
670670
int index, String selectorName, boolean hasDefault, Set<CtCase<?>> checked) {
671+
// no label matches and there is no default case: a switch expression then throws
671672
if (index == entries.size())
672-
return true; // no label matches and there is no default case
673+
return !(switchElement instanceof CtSwitchExpression<?, ?>);
673674
CaseEntry entry = entries.get(index);
674675
if (hasDefault && index == entries.size() - 1)
675676
return visitCasesFrom(switchElement, cases, entry.start(), checked);

0 commit comments

Comments
 (0)