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

Comma Operator breaks Functions that return never #47634

Closed
pushkine opened this issue Jan 27, 2022 · 1 comment
Closed

Comma Operator breaks Functions that return never #47634

pushkine opened this issue Jan 27, 2022 · 1 comment
Labels
Design Limitation Constraints of the existing architecture prevent this from being fixed

Comments

@pushkine
Copy link
Contributor

Bug Report

πŸ•— Version & Regression Information

ts stable & nightly

⏯ Playground Link

Playground Link

πŸ’» Code

function exit(): never {
    throw new Error();
}

function log_then_exit(): never {
    console.log();
    exit();
}

function log_then_exit_comma(): never {
    //                          ^^^^^ A function returning 'never' cannot have a reachable end point
    console.log(), exit();
}

πŸ™ Actual behavior

Error

πŸ™‚ Expected behavior

No Error

Related : #44487

@fatcerberus
Copy link

fatcerberus commented Jan 27, 2022

I believe this is expected because (per #32695 where the feature was implemented):

A function call is analyzed as an assertion call or never-returning call when

  • the call occurs as a top-level expression statement, and
  • the call specifies a single identifier or a dotted sequence of identifiers for the function name, and
  • each identifier in the function name references an entity with an explicit type, and
  • the function name resolves to a function type with an asserts return type or an explicit never return type annotation.

In your example, the call exit() is part of a comma expression, and thus not a top-level statement.

@RyanCavanaugh RyanCavanaugh added the Design Limitation Constraints of the existing architecture prevent this from being fixed label Feb 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Design Limitation Constraints of the existing architecture prevent this from being fixed
Projects
None yet
Development

No branches or pull requests

3 participants