Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Bug or breaking change in super constructors? #12669

Copy link
Copy link
@Elephant-Vessel

Description

@Elephant-Vessel
Issue body actions

TypeScript Version: 2.1.1 and nightly (2.2.0-dev.20161205)

Code

abstract class Animal
{
    constructor(someStr) { }

    public GetName() {
        return "test";
    }
}

class Dog extends Animal
{
    constructor()
    {
        super(super.GetName());
        var test = super.GetName();
    }
}

Expected behavior: (As per 2.0.10 and Playground)

var Dog = (function (_super) {
    __extends(Dog, _super);
    function Dog() {
        _super.call(this, _super.prototype.GetName.call(this)); // <= Look here
        var test = _super.prototype.GetName.call(this);
    }
    return Dog;
}(Animal));

Actual behavior:

var Dog = (function (_super) {
    __extends(Dog, _super);
    function Dog() {
        var _this = _super.call(this, _super.GetName.call(_this)) || this; // <= Look here
        var test = _super.prototype.GetName.call(_this);
        return _this;
    }
    return Dog;
}(Animal));

Notice the difference in the compiled call to _super.GetName/_super.prototype.GetName when super.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.

Reactions are currently unavailable

Metadata

Metadata

Assignees

Labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions

    Morty Proxy This is a proxified and sanitized view of the page, visit original site.