Simn / genjvm

13 stars 1 forks source link

Box-variance #51

Closed Simn closed 4 years ago

Simn commented 5 years ago

https://github.com/HaxeFoundation/haxe/issues/4342 is still a big problem. This code causes a NullPointerException:

class Main {
    static function main() {
        var n:Null<Int> = null;
        var closure:Null<Int>->Void = printA;
        closure(n);
    }

    static function printA(a:Int) {
        trace(a);
    }
}

This has to be solved when we detect the assignment of printA to closure, but I'm not sure what exactly we should do here. The notion of "adapter methods" has come up and I think MethodHandle supports that somehow, but my brain can't handle any more Java documentation for the moment.

Note that this fails on genjava too.

Simn commented 5 years ago

I think https://docs.oracle.com/javase/7/docs/api/java/lang/invoke/MethodHandles.html#foldArguments(java.lang.invoke.MethodHandle,%20java.lang.invoke.MethodHandle) is the answer here.

Simn commented 4 years ago

This now works fine with the new function representation.