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

scala.tools.nsc.javac.JavaParsers can't parse JDK14 records #11908

Closed
xuwei-k opened this issue Mar 16, 2020 · 6 comments · Fixed by scala/scala#9551
Closed

scala.tools.nsc.javac.JavaParsers can't parse JDK14 records #11908

xuwei-k opened this issue Mar 16, 2020 · 6 comments · Fixed by scala/scala#9551

Comments

@xuwei-k
Copy link

xuwei-k commented Mar 16, 2020

reproduction steps

https://openjdk.java.net/jeps/359

https://github.com/scala/scala/blob/a20345d2380dfc63ff0aa41d4ab97b538a9f74a7/src/compiler/scala/tools/nsc/javac/JavaParsers.scala#L874

$ java --version
openjdk 14 2020-03-17
OpenJDK Runtime Environment (build 14+36-1461)
OpenJDK 64-Bit Server VM (build 14+36-1461, mixed mode, sharing)

build.sbt

javacOptions ++= Seq("--enable-preview", "--release", "14")
scalaVersion := "2.13.1"

A.java

package aaa;

public record A(int x, int y) { }

B.scala

package bbb

class B {
  def x = new aaa.A(3, 4)
}

sbt version 1.3.8

problem

A.java:3:15: illegal start of type declaration
[error] public record A(int x, int y) { }
[error]               ^
[error] one error found
[error] (Compile / compileIncremental) Compilation failed

expectation

no error.

workaround

// build.sbt
compileOrder := CompileOrder.JavaThenScala
@mghildiy
Copy link

Is this taken up?

@SethTisue
Copy link
Member

@mghildiy nearly certain nobody is working on this

@mkurz
Copy link

mkurz commented Dec 15, 2020

records will be out of preview starting with Java 16, to be released in March: https://openjdk.java.net/jeps/395
Would be nice to see support in Scala soon.

@SethTisue
Copy link
Member

This would make an excellent project for an interested volunteer.

@harpocrates
Copy link

I'd be interested in picking this up.

Just to confirm: does scala.tools.nsc.javac.JavaParsers need to properly detect and error on all invalid Java code (eg. an abstract record), or is it OK to sometimes to accept Java code which javac will later reject? As I understand it, the critical bit is that if the Java source does compile, the output of JavaParsers must match the types/members javac produces.

@som-snytt
Copy link

@harpocrates yes iirc only what is required for interop.

I happen to be reading Plato atm. Socrates wrote nothing. Presumably, Harpocrates spoke nothing. Appreciate the midday chuckle.

harpocrates added a commit to harpocrates/scala that referenced this issue Mar 24, 2021
JDK16 introduced records (JEP 395) for reducing the boilerplate
associated with small immutable classes. This new construct
automatically

  * makes fields `private`/`final` and generates accessors for them
  * overrides `equals`/`hashCode`/`toString`
  * creates a `final` class that extends `java.lang.Record`

The details are in "8.10. Record Classes" of the Java language specification.

Fixes scala/bug#11908
harpocrates added a commit to harpocrates/scala that referenced this issue Apr 24, 2021
JDK16 introduced records (JEP 395) for reducing the boilerplate
associated with small immutable classes. This new construct
automatically

  * makes fields `private`/`final` and generates accessors for them
  * overrides `equals`/`hashCode`/`toString`
  * creates a `final` class that extends `java.lang.Record`

The details are in "8.10. Record Classes" of the Java language specification.

Fixes scala/bug#11908
@lrytz lrytz modified the milestones: Backlog, 2.13.7 Jul 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants