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

super() must not be called many times #23422

Closed
falsandtru opened this issue Apr 16, 2018 · 4 comments
Closed

super() must not be called many times #23422

falsandtru opened this issue Apr 16, 2018 · 4 comments
Labels
Out of Scope This idea sits outside of the TypeScript language design constraints

Comments

@falsandtru
Copy link
Contributor

Calling super() twice makes a runtime error.

TypeScript Version: 2.7.0-dev.201xxxxx

Search Terms:

Code

class C extends Object {
  constructor() {
    super();
    super();
  }
}

Expected behavior:

error

Actual behavior:

pass

Playground Link:

Related Issues:

@JoshuaKGoldberg
Copy link
Contributor

See discussion in palantir/tslint#1983

@falsandtru
Copy link
Contributor Author

It seems not standardized and still invalid now.

@mhegazy
Copy link
Contributor

mhegazy commented Apr 16, 2018

Not sure we can do more much here. In the general case the compiler can not gurantee how many times the method will be called. The check we can add is that the super call does not appear in a block more than once; first we do not have the infrastructure to do that, and second I think there will be false positives with conditions that the user know are mutually exclusive. This seems like a linter check to me.

@mhegazy mhegazy added the Out of Scope This idea sits outside of the TypeScript language design constraints label Apr 16, 2018
@falsandtru
Copy link
Contributor Author

Today, compiler seems to be changed to allow putting code before super call. So counting super calls is certainly difficult.

class C extends Object {
  constructor() {
    0
    super();
  }
}

@microsoft microsoft locked and limited conversation to collaborators Jul 25, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Out of Scope This idea sits outside of the TypeScript language design constraints
Projects
None yet
Development

No branches or pull requests

3 participants