Skip to content

Ensure/skip super call #12470

@ncannasse

Description

@ncannasse

In some code architecture, it is necessary for things to work correctly to always call the super method when you override it, and it can causes several issues when it's forgotten by some devs. Given this is general programming feature not specific to a given app or framework, I propose we introduce a @:callSuper metadata at the compiler level to enforce this.

class A {
     @:callSuper function init() { }
}
class B extends A {
     override function init() {
         // error super.init() was not called
     }
}
class C extends A {
    var initDone:Bool;
    override function init() {
         if( initDone ) return;
         trace("initializing");
         initDone = true;
         super.init();
        // we do not check all code paths to allow such patterns 
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions