Skip to content
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

The detection to unreachable code is inconsistent #55329

Closed
FlandreDaisuki opened this issue Aug 10, 2023 · 2 comments
Closed

The detection to unreachable code is inconsistent #55329

FlandreDaisuki opened this issue Aug 10, 2023 · 2 comments

Comments

@FlandreDaisuki
Copy link

FlandreDaisuki commented Aug 10, 2023

πŸ”Ž Search Terms

unreachable, reachability

πŸ•— Version & Regression Information

⏯ Playground Link

https://www.typescriptlang.org/play?ts=5.1.6#code/MYewdgzgLgBFAWAnEB3AWgU2TAvDAFAJS4B8MA3nEqjAAwwC+A3AFAsBmArmMFAJbgY7WkQosYEqsnRYQRVpJihIIADYYAdKpABzfAHIMADwAOGXjG6IMAQ2DwbAI3X7CrBmy49+g9gEZ8SgRpegYALgopVFoIqABPMxB2KJlsBmJycUlg6PksiWUINU1tPUNTc1grW3snFzcWDxYAE3NVG2shbl4BMBSAeTAMUQihgDcsVg5unz6delFMxRyUQeGGxULirV0DarsHZwwYGwgYYzNeDGbXd08Z3pgdPwIg6hQX8IoVv1iEjCSAyG6TEy3eAQ2ki26h2ZQulUsYGsBzqGFujTYhVgKwAKigQBFRDgyOMsLgCMRiZEVjAAEyMKZeHqCeALDL5FJ4uSQgrgIow0p7JE1Q7qE5neFXG4NJpM2YweAvQIpelfcgrWl-RLJXH4kFLbLvWl5TZ87aC8qXKrClFHdEMIA

πŸ’» Code

const throwZero = () => { throw 0 };

function f0() {
    throwZero();
    console.log('expect unreachable');
}

function f1({ throw0 }: { throw0: typeof throwZero }) {
    throw0();
    console.log('expect unreachable');
}
declare function throwOne() : never;

function g0 () {
    throwOne();
    console.log('unreachable as expected');
}

function g1 ({ throw1 }: {throw1: typeof throwOne}) {
    throw1();
    console.log('expect unreachable');
}

πŸ™ Actual behavior

In first code block:

The two console.log() are not identified as unreachable code.

In second code block:

It works at g0 declaration but not g1.

πŸ™‚ Expected behavior

They should be unreachable code.

@whzx5byb
Copy link

Duplicate of #53510

@FlandreDaisuki
Copy link
Author

@whzx5byb Thanks your help :D

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

2 participants