scala / scala3

The Scala 3 compiler, also known as Dotty.
https://dotty.epfl.ch
Apache License 2.0
5.87k stars 1.06k forks source link

Fails to compile java code with a valid java annotation syntax. #21319

Closed msosnicki closed 2 days ago

msosnicki commented 3 months ago

Compiler version

3.3.4

Minimized code

https://github.com/msosnicki/scala-annotations-java-issue

Piece of code that contains errors:

public record AnnotatedRecord(
  @JsonProperty("userId")
  java.util.@jakarta.validation.Valid Optional<scalac.issues.@jakarta.validation.Valid UserId> userId) {};

The code in the repo compiles fine in presence of sbt compileOrder := CompileOrder.ScalaThenJava settings. If it's removed, it is not compiling anymore (same as in 2.13.14).

Output

[error] -- Error: /home/ssn/code/scala/scala-annotations-java/src/main/java/scalac/issues/AnnotatedRecord.java:7:12
[error] 7 |  java.util.@jakarta.validation.Valid Optional<scalac.issues.@jakarta.validation.Valid UserId> userId) {};
[error]   |            ^^^^
[error]   |            identifier expected but @ found.
[error] -- Error: /home/ssn/code/scala/scala-annotations-java/src/main/java/scalac/issues/AnnotatedRecord.java:8:0
[error] 8 |
[error]   |^^^^^^
[error]   |identifier expected but eof found.
[error] two errors found

Expectation

Code compiles

som-snytt commented 3 months ago

Linking https://github.com/scala/scala3/issues/20026 and https://github.com/scala/scala3/pull/20064 where I said I would do more java annotation parsing.

Gedochao commented 2 months ago

cc @hamzaremmal @dwijnand