Repository navigation
fix(structure): An omitted OF/ELSE is not a branch of the CASE or IF around it - #873
Merged
msarson merged 1 commit intoNov 25, 2026
Merged
Conversation
…around it populateBranches() gave a CASE/IF every OF, OROF, ELSIF and ELSE inside it, including those in the body of an unconditional OMIT block. END pairing already treats an OMIT body as non-code, so the CASE card named the right END but listed a stray omitted ELSE among its branches, the "branch N of M" count was off, and an omitted OF hid the "OROF must be preceded by an OF" error. A branch keyword in an OMIT body now goes only to a CASE/IF opened in that body. Tests: 4 in OmitBodyStructures.test.ts, 3 in HoverProvider.CaseBranchList.test.ts; 6 fail without the fix. Full suite 4626 passing, 3 pending. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
msarson
added a commit
that referenced
this pull request
Nov 25, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
An omitted OF/ELSE is not a branch of the CASE or IF around it
What happened
A CASE with an unconditional OMIT block inside one of its branches. The block is dead code to the compiler, and it holds a stray
ELSEand oneENDmore than it opens:Hovering the CASE showed the omitted
ELSEas one of its branches:The END was right:
process()already reads an OMIT body as non-code (omittedLines(),omitFloor), so the extra END inside the block closes nothing. Only the branch list was wrong.Root cause
populateBranches()collects everyOF/OROF/ELSIF/ELSEtoken and gives each to the innermost CASE/IF open around it, with no regard for OMIT bodies:The same
branchesfeed the CASE, OF and END hover cards, the "branch N of M" text, and the OROF check inStructureDiagnostics.validateCaseStructures.The fix
process()passes the OMIT body flags it already computed, and a branch keyword in an OMIT body goes only to a CASE/IF opened in that body, as the body's ENDs do:Dropping omitted keywords altogether would be simpler but wrong: a CASE or IF written in the body keeps its own branches.
What this changes for the other readers of
branches:OF 'A'and the realELSE: 2 branches.ELSEsays "branch 3 of 3", not "4 of 4", in the test fixture.CASE a/OMIT('***')/OF 9/!***/OROF 2/END: the omitted OF used to hide "OROF must be preceded by an OF clause in CASE structure". The error now shows on the live OROF, as the compiler sees it.Testing
OmitBodyStructures.test.ts, new suite "A branch keyword in an OMIT body is not a branch of the structure around it" (4 tests): a CASE around a body with a stray OF and ELSE, a CASE and an IF written in the body keeping their own branches, an IF around a body with a stray ELSIF and ELSE, and the OROF error.HoverProvider.CaseBranchList.test.ts(3 tests): the CASE card and the END card list only the live branches, and the real ELSE card counts "3 of 3".An independent review also probed two OMIT blocks in one CASE, a body that leaves a CASE open, a CASE → IF → OMIT nesting, a conditional OMIT (unchanged, still read as code), an unterminated OMIT (unchanged), and a second
process()on the same tokens (identical result).Scope
DocumentStructureand stays code.leaveOmitBodyends that CASE on the same line. Nothing shows branches of omitted structures (hover is off in OMIT bodies, diagnostics there are filtered), so there is nothing to see.UnreachableCodeProviderhas the same blindness to OMIT bodies in its own branch-keyword scan: an omitted ELSE or RETURN changes which live lines are marked unreachable. That is a separate provider and is left for its own issue.