bug icon indicating copy to clipboard operation
bug copied to clipboard

scala.tools.nsc.javac.JavaParsers can't parse JDK17 "Sealed Classes"

Open xuwei-k opened this issue 4 years ago • 5 comments

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

xuwei-k avatar Sep 22 '20 01:09 xuwei-k

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 avatar Sep 22 '20 10:09 mkurz

@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.)

SethTisue avatar Oct 01 '20 01:10 SethTisue

it would make sense to tackle this and #12171 together

SethTisue avatar Jan 29 '21 14:01 SethTisue

@SethTisue Please also don't forget #11908 :wink:

mkurz avatar Jan 29 '21 15:01 mkurz

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/

mkurz avatar May 20 '21 10:05 mkurz