Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Signature vs. native type parameters #16

Closed
Simn opened this issue Mar 25, 2019 · 2 comments
Closed

Signature vs. native type parameters #16

Simn opened this issue Mar 25, 2019 · 2 comments

Comments

@Simn
Copy link
Owner

Simn commented Mar 25, 2019

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
Copy link
Owner Author

Simn commented Mar 25, 2019

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
Copy link
Owner Author

Simn commented Apr 3, 2019

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.

@Simn Simn closed this as completed in dd3fed2 Apr 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant