Skip to content

A break or continue naming a label no statement around it has is an error - #583

Merged
ASDAlexander77 merged 1 commit into
mainfrom
break-continue-label-error
Oct 17, 2026
Merged

ASDAlexander77 merged 1 commit into
mainfrom
break-continue-label-error

Conversation

@ASDAlexander77

Copy link
Copy Markdown
Owner

continue nolabel; and break nolabel; inside a loop compiled with no diagnostic: the jump op carried a label nothing matched.

Fix: MLIRGen keeps the labels of the statements around the code it is generating (activeLabels; pushed in mlirGen(LabeledStatement), cleared for a function body, since a jump can't leave a function) and rejects a labeled break/continue whose label isn't one of them.

Repro (diagnostic-location/continue_label.ts, break_label.ts):

function main() {
    outer: for (let i = 0; i < 3; i++) {
        for (let j = 0; j < 3; j++) {
            if (j == 1) continue outer;
            continue nolabel;   // 7:13: error: A 'continue' statement can only jump to a label of an enclosing statement
        }
    }
}

break_label.ts has a break outer inside an arrow function inside the labeled loop. That is an error, because the label is outside the function. A break outer after the arrow still compiles. The tests fail if a valid jump is reported.

Kept on purpose: continue lbl to a labeled block starts the block again (tests/00break_continue.ts test_label). TypeScript rejects it, but this compiler supports it deliberately, so only unknown labels are errors.

Not fixed, found while testing: a: b: for (...) { continue a; } loops forever (the loop's increment is skipped). That codegen bug was there before this PR.

ctest -C Release -j 8 --timeout 300: 100% passed, 0 failed (4093 tests on this branch).

🤖 Generated with Claude Code

…rror

`continue nolabel;` and `break nolabel;` inside a loop compiled with no
diagnostic: the jump op carried a label nothing matched. MLIRGen now
keeps the labels of the statements around the code it generates (a
function body starts with none, since a jump can't leave a function)
and rejects a label that isn't one of them.

A continue to the label of a block, which starts the block again
(tests/00break_continue.ts), stays: an extension TypeScript doesn't have.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ASDAlexander77
ASDAlexander77 merged commit 0b0a491 into main Oct 17, 2026
2 checks passed
@ASDAlexander77
ASDAlexander77 deleted the break-continue-label-error branch October 17, 2026 14:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant