Skip to content

Confusing error message for labels used before definition #30408

Description

The following gives me an unexpected "TS1007: Jump target cannot cross function boundary error" in TS 3.3.33333

function foo() {
    for (let i = 0; i < 10; i++) {
        console.log(`${i}`);
        continue loopend;
    }

    loopend:
    console.log('end of loop');
}

Further investigation... you can jump to the start of the loop, so the error I would argue is that the error message is confusing.

shareable link

Activity

  1. changed the title [-]Invalid "TS1007: Jump target cannot cross function boundary error" error in TS 3.3[/-] [+]Confusing error message for labels used before definition[/+] on Mar 14, 2019
  2. DanielRosenwasser commented on Mar 14, 2019

    @DanielRosenwasser
    Member

    Did you try adding 3s to the version to see if the error gets better?

    Seems like a reasonable request.

  3. DanielRosenwasser commented on Mar 14, 2019

    @DanielRosenwasser
    Member

    Here's a better message for this specific case, where the containing function of the label reference is the same as that of the labeled statement:

    A label cannot be referenced prior to its declared location.
    

    To find if it's applicable, walk up each scope until the first functionlike (isFunctionLike) or classlike (isClassLike) declaration and look for LabelledStatements in that scope.

    We can also provide a related span. We already have a diagnostic for

    {0} is declared here.
    
  4. paulvanbrenk commented on Mar 14, 2019

    @paulvanbrenk
    ContributorAuthor
  5. DanielRosenwasser commented on Mar 15, 2019

    @DanielRosenwasser
    Member

    Actually, we already have a better message for break or continue error messages.

  6. paulvanbrenk commented on Mar 15, 2019

    @paulvanbrenk
    ContributorAuthor
  7. laurafiuza commented on Mar 25, 2019

    @laurafiuza

    Hey -- is this still something that should be implemented? Happy to make changes now if no one else is already

  8. paulvanbrenk commented on Mar 28, 2019

    @paulvanbrenk
    ContributorAuthor

    Yes, please. This is still an issue in @next

  9. 9 remaining items

  10. mhughes2012 commented on Dec 23, 2025

    @mhughes2012

    I can take this on, I have a fix for it. Please assign me.

  11. added a commit that references this issue on Dec 24, 2025
    0b9ef8d
  12. added a commit that references this issue on Mar 26, 2026
    f16d4af
  13. added a commit that references this issue on Apr 6, 2026
    98d5745
  14. staticvariablejames commented on Apr 15, 2026

    @staticvariablejames

    I encountered a similar issue.

    setTimeout(() => {
        outerLoop: for(let i = 0; i < 3; i++) {
            break outerloop; // typo, "l" should be uppercase
        }
    });

    In this case the label does not exist, but I still get the error "TS1107: Jump target cannot cross function boundary."

    The problem still exists in version 7.0.0-dev.20260415.1 (with tsgo).

  15. added 3 commits that reference this issue on Apr 18, 2026
    23479df
    97e65a7
    d3db5eb
  16. LeonxLJX commented on Sep 1, 2026

    @LeonxLJX

    I'd like to take this one — I'll follow up with a PR. (claiming via Stella (@LeonxLJX))

  17. LeonxLJX commented on Sep 1, 2026

    @LeonxLJX

    Hi! I'd like to improve the 'label used before definition' error message. Plan: reproduce, refine the message, add tests. May I be assigned?

  18. anbv29 commented on Sep 14, 2026

    @anbv29

    Hey, i would like to work on this. Can i be assigned this issue?

  19. RyanCavanaugh commented on Sep 28, 2026

    @RyanCavanaugh
    Member

    Opening another PR for this issue without acknowledging that you're doing it - and what you're doing differently than the last seven - will be per se evidence of automated behavior and result in an immediate ban.

  20. locked and limited conversation to collaborators on Sep 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Domain: Error MessagesThe issue relates to error messagingEffort: ModerateRequires experience with the TypeScript codebase, but feasible. Harder than "Effort: Casual".Experience EnhancementNoncontroversial enhancementsGood First IssueWell scoped, documented and has the green lightHelp WantedYou can do thisSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions