fix(checker): emit precise error when labeled continue/break targets a non-enclosing label#63438
Closed
creazyfrog wants to merge 1 commit intomicrosoft:mainfrom
Closed
fix(checker): emit precise error when labeled continue/break targets a non-enclosing label#63438creazyfrog wants to merge 1 commit intomicrosoft:mainfrom
creazyfrog wants to merge 1 commit intomicrosoft:mainfrom
Conversation
…a non-enclosing label
When a labeled continue or break statement references a label that exists
in the same function but is not an ancestor (e.g. a forward reference or
a sibling statement), the checker walked up to the function boundary and
emitted TS1107 "Jump target cannot cross function boundary".
This message is misleading: the label is inside the same function, so
no function boundary is actually being crossed. The real problem is that
the label is not an *enclosing* statement.
Fix: before emitting TS1107 at a function boundary, check whether the
named label exists anywhere within that function scope via a new helper
`labelExistsInScope`. If it does, emit the more accurate diagnostic:
- TS1115: "A 'continue' statement can only jump to a label of an
enclosing iteration statement."
- TS1116: "A 'break' statement can only jump to a label of an enclosing
statement."
TS1107 is still emitted for the genuine cross-function case (label is in
an outer function).
Fixes microsoft#30408
Signed-off-by: creazyfrog <rohitcse.gec@gmail.com>
Member
|
Can you please tell me what tool you used to send this PR, and how you chose this issue to fix? |
Author
|
Hi Jake,
I used claude code to help me to generate the PR.
Just going through the list of issues in github, I found the issue to give a try.
Is it not as per the expectation?
…On Sun, Apr 26, 2026 at 8:18 AM Jake Bailey ***@***.***> wrote:
*jakebailey* left a comment (microsoft/TypeScript#63438)
<#63438 (comment)>
Can you please tell me what tool you used to send this PR, and how you
chose this issue to fix?
—
Reply to this email directly, view it on GitHub
<#63438 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AKHZN75AHT32OC3SVFQL3I34XYSFHAVCNFSM6AAAAACYGWTA3OVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHM2DGMRSGM2DGNBZGU>
.
Triage notifications, keep track of coding agent tasks and review pull
requests on the go with GitHub Mobile for iOS
<https://github.com/notifications/mobile/ios/AKHZN7YBNISEEKJD7SHC4QD4XYSFHA5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTIMZSGIZTIMZUHE22M4TFMFZW63VHNVSW45DJN5XKKZLWMVXHJKTGN5XXIZLSL5UW64Y>
and Android
<https://github.com/notifications/mobile/android/AKHZN76QCB3D6L6HRQ26CML4XYSFHA5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTIMZSGIZTIMZUHE22M4TFMFZW63VHNVSW45DJN5XKKZLWMVXHJLTGN5XXIZLSL5QW4ZDSN5UWI>.
Download it today!
You are receiving this because you were mentioned.Message ID:
***@***.***>
--
Rohit Sharma
IIIT-B
|
Member
|
Please read CONTRIBUTING.md |
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.
What this change intends to do
Fixes #30408
When a labeled
continueorbreakreferences a label that exists in the same function but is not an ancestor of the jump statement, TypeScript incorrectly emits:No function boundary is crossed — the label simply is not enclosing the jump. The misleading message causes developers to think they have a cross-function scoping problem when they actually have a non-enclosing label reference.
Fix
Adds a helper
labelExistsInScope(scope, labelName)that walks the AST children of the enclosing function-like node looking for a matchingLabeledStatement, without descending into nested function boundaries.In
checkGrammarBreakOrContinueStatement, when a function boundary is reached, the fix checks whether the named label exists anywhere in that function. If it does, it emits the accurate diagnostic instead of TS1107:continue— "A 'continue' statement can only jump to a label of an enclosing iteration statement."break— "A 'break' statement can only jump to a label of an enclosing statement."TS1107 is preserved for the genuine case where the label is defined in an outer function (a real function-boundary violation).
Before / After
The genuine cross-function case still produces TS1107 correctly:
File changed:
src/compiler/checker.ts— 22 insertions, 0 deletionsTests
This PR does not currently include a new compiler baseline test. A test in
tests/cases/compiler/covering:would be the right addition. I can add one if a maintainer confirms this approach before I invest the time, since baseline-accept changes require a full local build.
AI Assistance Disclosure
This PR was developed with the assistance of Claude Code (Anthropic), as required to be disclosed per the CONTRIBUTING.md guidelines.