haxe icon indicating copy to clipboard operation
haxe copied to clipboard

[Java/JVM] @:strict/@:meta doesn't support using annotations as arguments

Open TheDrawingCoder-Gamer opened this issue 2 years ago • 12 comments

Certain java annotation args require using other annotations, but haxe doesn't not allow this at the moment. Equivalent java code: @Foo(@Bar("baz")) Haxe code (doesn't work) @:meta(Foo(@:meta(Bar("baz")))) My current workaround just throws haxe out the window for anything that requires annotations and doing a dual stage build.

TheDrawingCoder-Gamer avatar Dec 01 '21 18:12 TheDrawingCoder-Gamer

Metadata cannot exist by itself, it always has to annotate something. That's why your example doesn't parse because just the metadata is not a valid expression. I don't know if there's a solution for this and I don't think I want to mess with this much. There have been ideas related to typed metadata floating around for a while, but nobody ever sat down to think this through properly.

Simn avatar Dec 01 '21 18:12 Simn

Yes, but this is strictly about java annotations, which this works with. If you can make a magic function that generates the annotation that's fine.

TheDrawingCoder-Gamer avatar Dec 01 '21 18:12 TheDrawingCoder-Gamer

Maybe in the java module or the java.Lib class?

TheDrawingCoder-Gamer avatar Dec 01 '21 18:12 TheDrawingCoder-Gamer

This is mostly a syntactic problem. Before we can do anything this has to be expressed in a way that is valid Haxe syntax. IMO it should still be handled via metadata because it is declarative in nature, but I'm not sure how exactly to map it...

Simn avatar Dec 01 '21 18:12 Simn

I don't really know. This feels like something that would be better fit to a HXP, because adding support for metadata as expressions is a really big deal. I just want to write my stuff in haxe :sob:

TheDrawingCoder-Gamer avatar Dec 02 '21 12:12 TheDrawingCoder-Gamer

I don't want to use metadata as standalone expression, I'm saying we need a different way to express this. Maybe something like @:meta($Foo($Bar("baz"))) which should be valid.

Simn avatar Dec 02 '21 12:12 Simn

I can see that, and that makes more sense. Of course this is a new syntax feature exclusively for java/cs annotations.

TheDrawingCoder-Gamer avatar Dec 02 '21 12:12 TheDrawingCoder-Gamer

Sure but so is @:meta, although I'm seeing that it also does something in the SWF-generator. But yes, we should determine the common denominator for all affected targets and then find a syntax that is sufficient to express everything. I suppose that was also the idea behind how @:meta works, but that approach is fundamentally flawed.

Simn avatar Dec 02 '21 12:12 Simn

I think the $Foo syntax is fine as it has a different syntax from regular, non-declarative functions and metadata.

TheDrawingCoder-Gamer avatar Dec 02 '21 13:12 TheDrawingCoder-Gamer

Has anything happened here? I'm coming back to using haxe for mods but this time under C#, and I don't think @:meta has been fixed

TheDrawingCoder-Gamer avatar Jan 18 '22 22:01 TheDrawingCoder-Gamer

I'm still not sure about the syntax so I was hoping someone would make a better suggestion...

Simn avatar Jan 18 '22 22:01 Simn

Merging #10749 will close this

TheDrawingCoder-Gamer avatar Jul 05 '22 19:07 TheDrawingCoder-Gamer

#10749 corrected the issue with untyped metadata, but @:strict still doesn't have a proper syntax to work with as far as I'm aware.

Is syntax still an issue here?

EliteMasterEric avatar Nov 24 '23 19:11 EliteMasterEric

At this point I think that @:strict needs its own mini-typer that deals with all the syntax. The original implementation tries to use the real Haxe typer, but it's quite awkward to manage. For meta inside meta we'll need some inner recursion to handle all the cases. I'll see what I can do.

Simn avatar Nov 24 '23 19:11 Simn

At this point I think that @:strict needs its own mini-typer that deals with all the syntax. The original implementation tries to use the real Haxe typer, but it's quite awkward to manage. For meta inside meta we'll need some inner recursion to handle all the cases. I'll see what I can do.

Curious on if there's been any investigation into the rewrites required for this to work and how those are progressing.

EliteMasterEric avatar Dec 16 '23 05:12 EliteMasterEric