-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Bug or breaking change in super constructors? #12669
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
Comments
I'll take a look, though this may be an error at runtime in native ES6. |
This should be an error. the emit is rather secondary (though we should fix it). |
also this should be an error, though it emits correctly: class Dog extends Animal {
constructor() {
var x = super.GetName(); // implicit use of `this` before it is defined
}
} |
Would you still be able to allow calls to super directly after the super-constructor is called, even if inside the derived constructor? The absence of any call to super in your above example made me unsure about your intentions. class Dog extends Animal {
constructor() {
super("foo");
var superName = super.GetName(); // Ok?
}
} |
This is valid code, and should work now anyways. the issue is the order. var _this = _super.call(this)) || this; so before this line, the rule the compiler should enforce is that |
We should definitely make this an error. Tested in NodeJS REPL:
|
Uh oh!
There was an error while loading. Please reload this page.
TypeScript Version: 2.1.1 and nightly (2.2.0-dev.20161205)
Code
Expected behavior: (As per 2.0.10 and Playground)
Actual behavior:
Notice the difference in the compiled call to
_super.GetName
/_super.prototype.GetName
whensuper.GetName
occurs in the super-constructor, while calls to_super.GetName
outside of the constructor always gets compiled to_super.prototype.GetName
.GetName is always attached to the prototype, so the
_super.GetName
is breaking runtime.Is there an intention, which would make sense, to disallow calls to super until after the constructor is run, only allowing static calls? Nevertheless, the generated code don't make sense and no compiler error is shown.
The text was updated successfully, but these errors were encountered: