Skip to content

"Unreachable code detected (7027)" false positive in 3.7 #34879

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
iyegoroff opened this issue Nov 2, 2019 · 3 comments
Closed

"Unreachable code detected (7027)" false positive in 3.7 #34879

iyegoroff opened this issue Nov 2, 2019 · 3 comments

Comments

@iyegoroff
Copy link

TypeScript Version: 3.7-beta, 3.7.1-rc, Nightly

Search Terms: declare never unreachable 7027

Code

declare function foo(): never

function bar() {
    foo()

    return 1
}

Expected behavior: no errors

Actual behavior: received error: "Unreachable code detected.(7027)"

Playground Link: https://www.typescriptlang.org/play/index.html?ts=3.8.0-dev.20191101#code/PTAEDMFcDsGMBcCWB7aFnIBQEpQG8AoEUEkgJwFN5Iy0BGUAQwGdRoKA3CsosAXwIEAJhVgAbRpQgwEKNOAw4AXG07dBUOElSgARpJz4CpdFmyCTlarVB0CAgkA

Related Issues: -

@MartinJohns
Copy link
Contributor

MartinJohns commented Nov 2, 2019

I would say this works as intended. The function foo declares that it will never return (by having never as the return-type). So the compiler correctly assumes that any code that comes after calling this method won't ever run.

Why do you consider this a false positive?

Related issue: #28859

@iyegoroff
Copy link
Author

@MartinJohns , @fatcerberus , thanks for the answers!

Why do you consider this a false positive?

Because it wasn't an error in 3.6 and https://www.typescriptlang.org/play/index.html?ts=3.8.0-dev.20191101&ssl=3&ssc=2&pln=1&pc=1#code/GYVwdgxgLglg9mABMOcAUBKRBvAUIgxAJwFMoQikBGRAQwGdEwSA3Eo3AX111ElgSIARrSKYc+QinQYehYmQrUuPIA also doesn't produce any errors

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