Simn / genjvm

13 stars 1 forks source link

Haxe extern vs. native signatures #13

Closed Simn closed 5 years ago

Simn commented 5 years ago

Math.floor is a good example:

class Main {
    @:analyzer(ignore)
    static public function main() {
        var d:Dynamic = Math;
        Sys.println(d.floor(f)); // 12.0
        Sys.println(Math.floor(f)); // Exception in thread "main" java.lang.NoSuchMethodError: java.lang.Math.floor(D)I
    }

    static var f = 12.5;
}

For the first one, the result has to be cast to Int. We cannot detect this at compile-time in the general case, so the dynamic resolution has to deal with this. This may be a good use-case for annotations.

In the second one we have to patch the signature at compile-time, but still make sure the result is cast back to Int. This is hardcoded in genjava, but I would like look into having a more flexible solution (metadata?).

Simn commented 5 years ago

I think we just have to accept the first situation. I can't think of a sane way to deal with this.

Simn commented 5 years ago

Given that this is only a problem if externs are inaccurate and that there's no reason for inaccurate externs other than the Math API, hardcoding this seems fair.