Skip to content

Allow classes to extend abstracts #11118

Description

@EliteMasterEric

Allowing classes to extend abstracts would be useful:

class Foo {
    public function new() {}

    public function value():Int { return 1; }
}

abstract Bar(Foo) {
    public function new() {
        this = new Foo();
    }

    // Calls to this function look like:
    // Bar_Impl_.doubleValue(foo_inst);
    public function doubleValue():Int {
        return 2 * this.value();
    }
}

// In the current version of Haxe, this would throw a compilation error.
// Instead, it should look like:
// class Baz extends Foo
class Baz extends Bar {
    public function new() {
        super();
    }

    // This function's body should look like:
    // return 2 * Bar_Impl_.doubleValue(this) + this.value();
    public function quintupleValue():Int {
        return 2 * this.doubleValue() + this.value();
    }

    // This should work as expected.
    public override function value():Int { return 3; }

    // This should throw a compilation error:
    // Cannot override a function declared in a parent abstract
    public override function doubleValue():Int;
}

If this is too big of a change to be considered a normal enhancement, let me know and I can draft a HaxeEvolution proposal.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions