scala / bug

Scala 2 bug reports only. Please, no questions — proper bug reports only.
https://scala-lang.org
230 stars 21 forks source link

JavaParsers doesn't support `JEP 445: Unnamed Classes and Instance Main Methods` #12878

Open xuwei-k opened 9 months ago

xuwei-k commented 9 months ago

Reproduction steps

A.java

void main() {
  System.out.println("hello");
}

B.scala

class B

build.sbt

javacOptions ++= Seq(
  "-Xlint:preview",
  "--enable-preview",
  "--release",
  scala.util.Properties.javaSpecVersion
)

scalaVersion := "2.13.12"

project/build.properties

sbt.version=1.9.6

Problem

sbt -J--enable-preview compile

https://github.com/scala/scala/blob/e67d287447c09720468f8bebcb0302bd92d75f43/src/compiler/scala/tools/nsc/javac/JavaParsers.scala#L1074

[error] /home/runner/work/Scala-JEP-445/Scala-JEP-445/A.java:1:6: illegal start of type declaration
[error] void main() {
[error]      ^
[error] one error found
[error] (Compile / compileIncremental) Compilation failed