Skip to content

The addition of a continue statement makes the compilation fail #51632

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
rosenblueh opened this issue Nov 23, 2022 · 5 comments
Closed

The addition of a continue statement makes the compilation fail #51632

rosenblueh opened this issue Nov 23, 2022 · 5 comments

Comments

@rosenblueh
Copy link

Bug Report

The addition of a continue statement in a for loop make some code unreachable (see screenshots below).
After the addition of the continue statement the unreachable part of the code gives compilation errors. The errors are also highlighted in VS Code.
If no continue statement is present everything compiles without an error.

🔎 Search Terms

continue

🕗 Version & Regression Information

I saw the bug today, in tsc version 4.8.4

Please keep and fill in the line that best applies:
-->

  • This is a crash

🙁 Actual behavior

Not working:
non_working

Working
working

🙂 Expected behavior

The addition of the continue statement shouldn't yield additional compilation errors, especially since they happen in unreachable code.

@fatcerberus
Copy link

Because the code is unreachable, the type narrowing machinery essentially can’t see it. Duplicate of #26914

@rosenblueh
Copy link
Author

Can't the type narrowing machinery be turned off for unreachable code?

@fatcerberus
Copy link

fatcerberus commented Nov 23, 2022

Can't the type narrowing machinery be turned off for unreachable code?

Well, in a way it already is - any existing narrowings get undone the minute the subsequent code is determined to be unreachable, hence the type errors. You probably meant to ask if type checking can be turned off, and while that’d be an option, there are reasons to keep it on - see #26914 (comment).

Note that 26914 is tagged as a bug - it’s something they do want to fix, despite the current design limitations.

@jcalz
Copy link
Contributor

jcalz commented Nov 23, 2022

The bug report template asks for plaintext code and a Playground link. A screenshot isn't appropriate for various reasons: you can't copy and paste it into an IDE without an image-to-text step; it's less accessible for visually impaired users who otherwise are able to code; et cetera.

Also, this isn't a crash. (Maybe the template should be edited to define the term?) A crash is when the compiler itself fails to run, not when it merely reports warnings for the code it's compiling. If the compiler were a professor and your code were an exam to be graded, it isn't a crash if you disagree with the grade. A crash would be that the professor has a heart attack and dies while grading your exam.

@rosenblueh
Copy link
Author

Thanks for your feedback. I suspected this was already reported in some way. If it would have turned out to be a new bug, I could have provided a playground link.

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

No branches or pull requests

3 participants