benmerckx / genes

Generates split ES6 modules and Typescript definitions from Haxe modules.
43 stars 8 forks source link

Problem with haxe.Exception #40

Closed kevinresol closed 3 years ago

kevinresol commented 3 years ago
class Main {
    static function main() {
        trace(new haxe.Exception('foo').message);
    }
}

generated:

export const Exception = Register.global("$hxClasses")["haxe.Exception"] = 
class Exception extends Register.inherits(Error) {
    new(message, previous = null, $native = null) {
        Error.call(this, message);
        this.message = message;
        this.__previousException = previous;
        this.__nativeException = ($native != null) ? $native : this;
    }
    get message() {
        return this.get_message()
    }
    get_message() {
        return this.message;
    }
    static get __name__() {
        return "haxe.Exception"
    }
    static get __super__() {
        return Error
    }
    get __class__() {
        return Exception
    }
}

Note that the line this.message = message will fail because message has no native setter.

Also, trying to access .message will cause a stack overflow because get message() and get_message() are mutually recursive.

benmerckx commented 3 years ago

That's some odd code there, I guess it's only so it passes the @:coreApi constraint