janino-compiler / janino

Janino is a super-small, super-fast Java™ compiler.
http://janino-compiler.github.io/janino
Other
1.21k stars 205 forks source link

Correctly parse and unparse annotated wildcard types #214

Closed Geolykt closed 5 months ago

Geolykt commented 5 months ago

Note that this does not mean that the wildcard annotations show up when compiled. I've had little luck with getting janino to produce signatures in the class bytecode in the first place. Hence the tests relevant to this PR are only constrained to the Unparser while the larger compile tests were left alone.

The fact that wildcard tpyes can be annotated is not really well defined within the JLS: The only definition of this behaviour can be found in JLS8, 4.5.1 within the syntax of wildcards, which is then repeated in JLS8 section 18. But there is otherwise no supporting evidence. Outside the JLS, JVMS8, section 4.7.20.2 lists a few examples on where annotations appear, one of which is our wildcard annotation. It also seems to define that annotations which are on the right hand of a wildcard have a type_path_kind value of 2. Those on the left hand (which this PR implements) are not directly associated with the wildcard and have a type_path_kind value of 3 (as they referr to the type represented by the wildcard, not the bounds)


Note that local variable declarations seem to not support annotated types, this PR does not touch those and as such annotating the type arguments for them still continues to fail - with and without wildcards.

Also, I am aware that the Unparser test contains code that shouldn't compile, but I expect this to not be a concern since the code will never get compiled anyways. Should my expectation be false, please do notify me about that however.

aunkrig commented 5 months ago

Lovely, comes even with a test case! Thanks for your contribution.