opened
paulvanbrenk
username_0
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');
}
```

[shareable link](https://www.typescriptlang.org/play/#src=%0D%0Afunction%20foo()%20%7B%0D%0A%20%20%20%20for%20(let%20i%20%3D%200%3B%20i%20%3C%2010%3B%20i%2B%2B)%20%7B%0D%0A%20%20%20%20%20%20%20%20console.log(%60%24%7Bi%7D%60)%3B%0D%0A%20%20%20%20%20%20%20%20continue%20loopend%3B%0D%0A%20%20%20%20%7D%0D%0A%0D%0A%20%20%20%20loopend%3A%0D%0A%20%20%20%20console.log('end%20of%20loop')%3B%0D%0A%7D%0D%0A)
Invalid "TS1007: Jump target cannot cross function boundary error" error in TS 3.3
issue
created
DanielRosenwasser
username_1
~Did you try adding `3`s to the version to see if the error gets better?~

Seems like a reasonable request.
comment
created
DanielRosenwasser
username_1
Here's a better message for this specific case.

```
A label cannot be referenced prior to its declared location.
```

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

```
{0} is declared here.
```
comment
created
paulvanbrenk
username_0
??????

Get Outlook for Android<https://aka.ms/ghei36>
comment
created
DanielRosenwasser
username_1
Actually, we already have a better message for `break` or `continue` error messages.
comment
created
paulvanbrenk
username_0
In 3.4?

Get Outlook for Android<https://aka.ms/ghei36>
comment
created
laurafiuza
username_2
Hey -- is this still something that should be implemented? Happy to make changes now if no one else is already
comment
created
paulvanbrenk
username_0
Yes, please. This is still an issue in @next
comment
created
DanielRosenwasser
username_1
It may be a bit more work than I originally anticipated (since labels aren't placed in any sort of scope), but we're taking PRs if you're up for it.

I guess if you can walk up the tree and look for labels in each enclosing scope, then:

* If the label actually contains the source of the `break`/`continue`, but it crosses a function boundary, you can continue to give the same error message.
* If the label doesn't contain the origin of the `break`/`continue`, then give an error like

  ```
  Labels cannot be referenced outside of statements which they label.
  ```
* Otherwise, give a message like

  ```
  Cannot find label '{0}'.
  ```

In the first two, give the appropriate related span mentioned above.
comment
created
karthikkp
username_3
@username_2 Still working on this?
comment
created
karthikkp
username_3
@username_1 For point #1, we will have to go through the entire set of statements in the source file to check if the label exists as, as soon as we travel up the tree and go beyond the function boundry we get the source file in the example in the first example. To simply put we will have to check the siblings of the function statement. Is my understanding right?
comment
created
DanielRosenwasser
username_1
Just scan through the statements at each level until you hit a function-like/class-like - don't try to walk recursively.
comment
created
karthikkp
username_3
This is what is already being done. The cross boundary error is returned as soon as the first functionlike statment is found.
comment
created
malikasinger1
username_4
you could have thrown a better error message, talking about this: https://stackoverflow.com/questions/59859011/break-says-error-jump-target-cannot-cross-function-boundary-typescript/59859151#59859151
comment