scala / bug

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

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

Open xuwei-k opened 5 months ago

xuwei-k commented 5 months 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 5 months 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

SethTisue commented 3 months ago

would it be useful for our parser to accept but ignore such imports? or does it need to actually take action in order for the change to be useful?