HaxeFoundation / haxe

Haxe - The Cross-Platform Toolkit
https://haxe.org
6.03k stars 648 forks source link

Accessing super from a local function #11672

Closed Speedphoenix closed 1 month ago

Speedphoenix commented 1 month ago

I have a case like this

class A {
    function trySomething() {
        trace("tried");
    }
}

class B extends A {
    function askConfirm(onConfirm:Void->Void) {}

    override function trySomething() {
        function continueTrying() {
            trace("more stuff");
            super.trySomething();
        }
        if (true) {
            askConfirm(() -> continueTrying());
        } else {
            continueTrying();
        }
    }
}

but super.trySomething() gives me

Cannot access super inside a local function Try Haxe

So I need to create a separate same-scope function that is meant to be used exclusively inside trySomething(), which I would rather not have to do

Is there any chance we'd be able to use super in local functions in the future?

Simn commented 1 month ago

No, this cannot be implemented on all targets.