scala / bug

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

support `JEP 476: Module Import Declarations` in `JavaParsers` #13005

Open xuwei-k opened 3 weeks ago

xuwei-k commented 3 weeks ago

Reproduction steps

https://openjdk.org/jeps/476

Scala version: 2.13.14

$ java --version
openjdk 23-ea 2024-09-17
OpenJDK Runtime Environment (build 23-ea+25-2094)
OpenJDK 64-Bit Server VM (build 23-ea+25-2094, mixed mode, sharing)

B.scala

class B

A.java

import module java.base;

public class A {
}

build.sbt

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

scalaVersion := "2.13.14"

project/build.properties

sbt.version=1.10.0

Problem

run sbt compile

[error] my-example-project-path/A.java:1:15: `;` expected but identifier found.
[error] import module java.base;
[error]               ^
[error] one error found
[error] (Compile / compileIncremental) Compilation failed

workaround

set compileOrder := CompileOrder.JavaThenScala or compileOrder := CompileOrder.ScalaThenJava in sbt

som-snytt commented 3 weeks ago

The Java feature is mostly about prototyping and JShell. It would be nice if -Yimports handled modules.

scala -Yimports:java.lang,scala,scala.Predef,scala.annotation,scala.util.chaining becomes scala -Yimports:java.base,scala,scala.Predef,scala.annotation,scala.util.chaining where for conflicts between module and package names it could support scala -Yimports:module java.base,etc or someday just scala -Yimports:java.base,scala.base