Skip to content

Parse Java annotations on wildcard type arguments#26187

Open
mkurz wants to merge 1 commit into
scala:mainfrom
mkurz:fix-java-annotated-wildcards
Open

Parse Java annotations on wildcard type arguments#26187
mkurz wants to merge 1 commit into
scala:mainfrom
mkurz:fix-java-annotated-wildcards

Conversation

@mkurz
Copy link
Copy Markdown
Contributor

@mkurz mkurz commented May 29, 2026

Java permits type-use annotations before wildcard type arguments, for example

Function<@Nullable ? super String, @Nullable ? extends Object>

Reproduce

You can use this repo's test files:

$ cd tests/pos/java-annotated-wildcards/

$ scala -version
Scala code runner version: 1.12.4
Scala version (default): 3.8.3

$ scalac -usejavacp Nullable.java Test.java 
-- Error: Test.java:4:21 ---------------------------------------------------------------------------------------------------------------------------
4 |  Function<@Nullable ? super String, @Nullable ? extends Object> mappingFunction();
  |                     ^^^^^^^^
  |                     illegal start of type
-- Error: Test.java:4:82 ---------------------------------------------------------------------------------------------------------------------------
4 |  Function<@Nullable ? super String, @Nullable ? extends Object> mappingFunction();
  |                                                                                  ^
  |                                                                                  null expected but ';' found.
  |
5 |}
2 errors found

Java however can compile it:

$ java -version
openjdk version "1.8.0_492"
OpenJDK Runtime Environment (Temurin)(build 1.8.0_492-b09)
OpenJDK 64-Bit Server VM (Temurin)(build 25.492-b09, mixed mode)

$ javac Nullable.java Test.java 
$ ls -1 *.class
Nullable.class
Test.class

How much have you relied on LLM-based tools in this contribution?

Not at all (update: after the GitHub actions jobs failed I used codex for analysing the code and find out what broke, that lead to force push)

How was the solution tested?

New automated tests (including the issue's reproducer)
Plus Manual tests

See also

Java permits type-use annotations before wildcard type arguments, for
example Function<@nullable ? super String, @nullable ? extends Object>.

Consume annotations before checking for a wildcard type argument so the
Java parser accepts that syntax. Add a positive Java parser regression
test covering annotated wildcard bounds.
@mkurz
Copy link
Copy Markdown
Contributor Author

mkurz commented May 30, 2026

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.

1 participant