bug
bug copied to clipboard
scala.tools.nsc.javac.JavaParsers can't parse JDK17 "Sealed Classes"
reproduction steps
https://openjdk.java.net/jeps/360 https://github.com/scala/scala/blob/v2.13.3/src/compiler/scala/tools/nsc/javac/JavaParsers.scala#L1002
$ java --version
openjdk 15 2020-09-15
OpenJDK Runtime Environment (build 15+36-1562)
OpenJDK 64-Bit Server VM (build 15+36-1562, mixed mode, sharing)
build.sbt
javacOptions ++= Seq("--enable-preview", "--release", "15")
scalaVersion := "2.13.3"
A.java
sealed class A{}
final class B extends A{}
C.scala
class C
sbt version: 1.3.13
problem
run sbt compile
A.java:1:8: illegal start of type declaration
[error] sealed class A{}
[error] ^
[error] one error found
[error] (Compile / compileIncremental) Compilation failed
[error] Total time: 0 s, completed 2020/09/22 10:18:53
workaround
// build.sbt
compileOrder := CompileOrder.JavaThenScala
note
similar issue https://github.com/scala/bug/issues/11908
Not really sure if this is somehow related, but ASM 9.0, which brings support for Java 15 and even Java 16 already just got released:
- https://gitlab.ow2.org/asm/asm/-/tags/ASM_9_0
- https://repo1.maven.org/maven2/org/ow2/asm/asm/9.0/
- https://asm.ow2.io/versions.html
@mkurz this ticket is about mixed compilation of Scala and Java sources. ASM involves JVM bytecode only, not Java source code.
(regardless, thanks for calling the ASM upgrade to our attention, we'll evaluate that soon, plus I'll be embarking on https://github.com/scala/community-build/issues/1225 soon.)
it would make sense to tackle this and #12171 together
@SethTisue Please also don't forget #11908 :wink:
Sealed Classes (JEP 409) was just merged into the Java 17 dev repo:
- https://github.com/openjdk/jdk/pull/3526
- Commit: https://github.com/openjdk/jdk/commit/0fa9223f34bc33635079763362f42f0a5c53759b
- https://github.com/openjdk/jdk/pull/3528
- Commit: https://github.com/openjdk/jdk/commit/31b98e129e6d3051c01775519792b2ba5745b275
- https://github.com/openjdk/jdk/pull/3613
- Commit: https://github.com/openjdk/jdk/commit/7dcb9fda89ee17a5eadc83999de21e4542f37133
Also see https://openjdk.java.net/projects/jdk/17/