Java records in mixed Java/Scala 3 project

I see that support for Java records was added in 2.13.7. However, I’m still running into troubles in 3.1.1 (sbt 1.6.2):

[error] -- Error: /.../src/main/java/Foo.java:1:14 ------------------
[error] 1 |public record Foo(int value) {
[error]   |              ^^^
[error]   |              illegal start of type declaration

Is this something that’s supposed to be working? I couldn’t find a related issue on GitHub.
Note that the code works in 2.13.8, and also in 3.1.1 if all the Scala code is removed (i.e., as a pure Java project).

They are different codebases evolving at different rates in different directions, so I think that hasn’t been forward-ported yet.

Understood. Do you know if there is a ticket somewhere I can track? Records were finalized in Java 16 (and 18 is out!). It’s only been a year, but it’s a bit annoying not to have them. (I have several projects in Java with tests in Scala, so I may care more about Java support than other Scala developers.)

I’ve opened Support parsing record classes in Java source files · Issue #14846 · lampepfl/dotty · GitHub.

1 Like

There were PRs for triple quote strings and records. I’ll start with a swing at triple quotes, in case that is easier. As usual, the hard part is the test.

Hey, Can you run your program on this online java compiler - Online Java Compiler | Java IDE Online - InterviewBit and save your snippet and share it here, So we will check the whole error?

The question is how scalac parses java source in mixed compilation. Otherwise, scalac assumes the available javac consumes java source.

1 Like