Skip to content

Code following truthiness assertion with false argument is unreachable#33831

Merged
ahejlsberg merged 7 commits into
masterfrom
falseAssertions
Oct 9, 2019
Merged

Code following truthiness assertion with false argument is unreachable#33831
ahejlsberg merged 7 commits into
masterfrom
falseAssertions

Conversation

@ahejlsberg
Copy link
Copy Markdown
Member

With this PR we consider code following a truthiness assertion with a false argument to be unreachable. For example:

// Compile with --allowUnreachableCode false

function assert(expr: unknown): asserts expr {
    if (!expr) {
        throw new Error("Assertion failed");
    }
}

function foo() {
    assert(false);
    console.log("unreachable");  // Unreachable code error
}

Fixes #33805.

@ahejlsberg ahejlsberg merged commit 6104f74 into master Oct 9, 2019
@ahejlsberg ahejlsberg deleted the falseAssertions branch October 9, 2019 20:23
@microsoft microsoft locked as resolved and limited conversation to collaborators Oct 21, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

A false assertion should be considered as never-returning

2 participants