Repository navigation
Check each case of a switch from the state before it - #497
Conversation
A switch is checked as the chain of ifs that tests its labels: each case knows the selector equals one of its labels (the default case, none of the others), starts from the state before the switch, falls through into the next case when it does not break, and the states of the cases that reach the end are joined after it. Switch expressions are checked the same way. Pattern and guarded cases keep the previous checking. A break or yield nested inside a case's statements is not followed: what those cases change is forgotten on that path. Fixes #494 Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Codex review, round 1
|
…er it Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Round 1 replies:
|
|
Codex review, round 2: no findings ("I found no actionable regressions in the diff. The verifier test suite passed."). |
Clean-code review (clean-code-principles)Reviewed the diff only, weighed against the standing rules (smallest PR that tests well, match surrounding style, no tidy-only refactors, lean tests). Nothing worth a commit and CI run; no new commits.
|
Fixes #494
The verifier had no
switchhandling, so the cases ran one after another as straight-line code:breakwas ignored and thecaselabel never entered the path condition. Aswitchis now checked like theif/else ifchain over its labels:selector == label(grouped labels: any of them;default: none of the other labels)breakfalls through into the next oneifreturn/throw/continuein a case drop that path, as in anif->,yield) are checked the same way; selectors may be enums, ints or strings (a string label has no known value, so it adds no path condition)Two forms are handled conservatively:
case String s ->,when): checked as before (Verifier crashes on a type-pattern switch (case String s ->) #345 is unchanged)break/yieldnested inside a case (e.g.if (c) { ...; break; }): the state at that jump is not followed, so what those cases change is forgotten on that path after the switch (shown astruein Found)Study exercise A1_09 (litiengine), the partial fix
else if (newMode == BORDERLESS) host.dispose();Before, the same error at the same line, though BORDERLESS is now disposed:
After, the error moves to the remaining bug, the full-screen fallback:
Study exercise A1_56 (JabRef), only
redo()guardedBefore, the UNDO case saw what the REDO case did:
After, only what holds on the UNDO path:
The six study exercises still report their error at the same line. A1_09's Found now starts with the case's label:
found newMode == BORDERLESS && (...). The other study variants report the same as before, apart from A1_09's first-only fix: same line (63), but its Found wasdisplayable(host), the state the BORDERLESS case left, and is now the full-screen path'snewMode == FULLSCREEN && (...), longer than before.Tests:
CorrectEnumUsage(state and label of each case, switch statement and expression),ErrorEnumUsage(an error that was missed in a case reached directly and by fall-through, and the nestedbreak).TestStateHintsnow expects A1_56's UNDO hints above. Each fails onmain.🤖 Generated with Claude Code