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

Correctly parse and unparse annotated wildcard types #214

Merged
merged 1 commit into from
Feb 15, 2024

Conversation

Geolykt
Copy link
Contributor

@Geolykt Geolykt commented Feb 11, 2024

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.

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 commit 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 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)
Copy link
Member

@aunkrig aunkrig left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks all fine to me.

@aunkrig aunkrig merged commit 4db1b81 into janino-compiler:master Feb 15, 2024
@aunkrig
Copy link
Member

aunkrig commented Feb 15, 2024

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

@Geolykt Geolykt deleted the wildcard-type-annots branch February 15, 2024 14:10
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

Successfully merging this pull request may close these issues.

2 participants