Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

scala-cli eagerly sets -release / -java-output-version, which prevents compiling on new Java versions #3115

Closed
lrytz opened this issue Aug 19, 2024 · 3 comments · Fixed by #3119
Assignees
Labels
Bloop Issues tied with Bloop integration. bug Something isn't working jvm Issues tied to the JVM platform scalac compatibility Issues tied with compatibility with the scalac (compiler) command.

Comments

@lrytz
Copy link

lrytz commented Aug 19, 2024

scala-cli compile always sets -release N (aka -java-output-version on Scala 3) where N is the Java version.

This prevents compiling on a Java version which is not yet known to the compiler:

➜ sandbox cat A.scala
class A { java.io.IO.print(1) }

➜ sandbox scala compile --server=false -S 3 A.scala
23 is not a valid choice for -java-output-version
  scalac -help  gives more information
Compilation failed

I can manually set an older -release version, but then new API is not available:

➜ sandbox scala compile --server=false -S 3 A.scala -O -release -O 22
-- [E008] Not Found Error: /Users/luc/code/scala/scala13/sandbox/A.scala:1:18 --
1 |class A { java.io.IO.print(1) }
  |          ^^^^^^^^^^
  |          value IO is not a member of java.io
1 error found
Compilation failed

Invoking the compiler manually works, the compiler writes the classfile using the default version 52 (corresponds to Java 8):

➜ sandbox java -cp $(cs fetch -p org.scala-lang::scala3-compiler:3.5.0) dotty.tools.dotc.Main -usejavacp A.scala
➜ sandbox asm A.class && cat A.asm
// class version 52.0 (52)
// access flags 0x21
public class A {

  // compiled from: A.scala
...

@Gedochao mentioned that the flag might have been added due to some interaction with bloop (cc @kasiaMarek, @tgodzik)

@lrytz lrytz added the bug Something isn't working label Aug 19, 2024
@Gedochao Gedochao added Bloop Issues tied with Bloop integration. jvm Issues tied to the JVM platform scalac compatibility Issues tied with compatibility with the scalac (compiler) command. labels Aug 19, 2024
@kasiaMarek
Copy link
Collaborator

kasiaMarek commented Aug 19, 2024

The flag is not added for bloop, bloop handles adding this flag on its own. It is added when server=false.

val releaseFlagVersion =
if (options.useBuildServer.getOrElse(true)) None
else releaseFlag(options, compilerJvmVersionOpt, logger).map(_.toString)

Probably we could avoid adding it if scala compiler jdk matches required jdk, but checking the jvm version for simple compiler seems to be missing an implementation:

def jvmVersion: Option[Positioned[Int]] =
None // ??? TODO

@lrytz
Copy link
Author

lrytz commented Aug 19, 2024

Ah, I'm indeed using --server=false

bloop handles adding this flag on its own

So is also setting -release? Then maybe it was done for consistency with bloop?

What is the "required jdk" you mention?

@kasiaMarek
Copy link
Collaborator

What is the "required jdk" you mention?

I just mean the one Scala CLI calculates from options like jvm xx.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bloop Issues tied with Bloop integration. bug Something isn't working jvm Issues tied to the JVM platform scalac compatibility Issues tied with compatibility with the scalac (compiler) command.
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

3 participants