Simn / genjvm

13 stars 1 forks source link

Signature vs. native type parameters #16

Closed Simn closed 5 years ago

Simn commented 5 years ago

This currently errors:

import java.jvm.annotation.EnumReflectionInformation;

class Main {
    static public function main() {
        var exprDefClass = Type.resolveClass("haxe.macro.ExprDef");
        var exprDefNative = exprDefClass.native(); // same value but typed as java.lang.Class
        var annotation:java.lang.annotation.Annotation = exprDefNative.getAnnotation(cast EnumReflectionInformation);
    }
}

java.lang.NoSuchMethodError: java.lang.Class.getAnnotation(Ljava/lang/Class;)Ljava/lang/Object;

I think it's because of the return type being `Ljava/lang/Object;``.

The Haxe dump looks fine:

[Var annotation(1388):java.lang.annotation.Annotation]
    [Call:java.lang.annotation.Annotation]
        [Field:(param1 : java.lang.Class<java.lang.annotation.Annotation>) -> java.lang.annotation.Annotation]
            [Local exprDefNative(1387):java.lang.Class<Dynamic>:java.lang.Class<Dynamic>]
            [FInstance:(param1 : java.lang.Class<java.lang.annotation.Annotation>) -> java.lang.annotation.Annotation]
                java.lang.Class<Dynamic>
                getAnnotation:(param1 : java.lang.Class<getAnnotation.A>) -> getAnnotation.A
        [Cast:java.lang.Class<java.lang.annotation.Annotation>] [TypeExpr haxe.jvm.annotation.EnumReflectionInformation:Class<java.jvm.annotation.EnumReflectionInformation>]

I have to check that the generator uses the correct type for this.

Simn commented 5 years ago

This seems a bit tricky. The JVM wants us to use the applied type parameters, but we can't just drop the type of FInstance in there because that might contain basic types, and these are not assignable to type parameters without boxing. This means that we would have to know which basic types were assigned to type parameters, but I don't think we retain this information in our typed AST.

I think we could apply + box the class type parameters, but we can't do that with field type parameters because we don't have a type list for them.

Hmm...

Simn commented 5 years ago

I think what we're actually supposed to do here is generate singly-constrained type parameters as their constraint type. We have to be careful with #30 though.