Skip to content

Calling super methods returning never does not contribute to CFA #36147

@Gerrit0

Description

@Gerrit0

TypeScript Version: 3.7.2, Nightly

Search Terms: super control flow analysis never, super returning never

Expected behavior: No error on SuperThrowable.err, or an error on both SuperThrowable.err and SuperThrowable.ok

Actual behavior: A function returning 'never' cannot have a reachable end point.(2534)

Related Issues: Quite a few regarding CFA, but none related to super vs this. Discovered from this SO question

Code

class MyThrowable {
    throw(): never {
        throw new Error();
    }
}

class SuperThrowable extends MyThrowable {
    /// A function returning 'never' cannot have a reachable end point.(2534)
    err(msg: string): never {
        super.throw()
    }

    // Ok
    ok(): never {
        this.throw()
    }
}
Output
"use strict";
class MyThrowable {
    throw() {
        throw new Error();
    }
}
class SuperThrowable extends MyThrowable {
    /// A function returning 'never' cannot have a reachable end point.(2534)
    err(msg) {
        super.throw();
    }
    // Ok
    ok() {
        this.throw();
    }
}
Compiler Options
{
  "compilerOptions": {
    "noImplicitAny": true,
    "strictNullChecks": true,
    "strictFunctionTypes": true,
    "strictPropertyInitialization": true,
    "strictBindCallApply": true,
    "noImplicitThis": true,
    "noImplicitReturns": true,
    "useDefineForClassFields": false,
    "alwaysStrict": true,
    "allowUnreachableCode": false,
    "allowUnusedLabels": false,
    "downlevelIteration": false,
    "noEmitHelpers": false,
    "noLib": false,
    "noStrictGenericChecks": false,
    "noUnusedLocals": false,
    "noUnusedParameters": false,
    "esModuleInterop": true,
    "preserveConstEnums": false,
    "removeComments": false,
    "skipLibCheck": false,
    "checkJs": false,
    "allowJs": false,
    "declaration": true,
    "experimentalDecorators": false,
    "emitDecoratorMetadata": false,
    "target": "ES2017",
    "module": "ESNext"
  }
}

Playground Link: Provided

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFix AvailableA PR has been opened for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions