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

String interpolation fails to compile running on JDK 20 when using release:11 compiler option #12761

Closed
arixmkii opened this issue Mar 27, 2023 · 3 comments · Fixed by scala/scala#10359
Assignees
Milestone

Comments

@arixmkii
Copy link

Reproduction steps

Scala version: 2.13.10

object A {
  def a(s: String): String = s"S: $s"
}

Problem

When trying to compile on JDK 20:

% java -version             
openjdk version "20" 2023-03-21
OpenJDK Runtime Environment Temurin-20+36 (build 20+36)
OpenJDK 64-Bit Server VM Temurin-20+36 (build 20+36, mixed mode)

% scala -version
Scala code runner version 2.13.10 -- Copyright 2002-2022, LAMP/EPFL and Lightbend, Inc.

% scalac -release:11 A.scala
error: Error while emitting A$
Unsupported class file major version 64
1 error

Compiles just fine with Temuring 17 JDK.

Platforms tested on:

  • macOS arm64
@som-snytt
Copy link

And I just joked that "adding strings" was the only API I never need to consult the docs about.

@som-snytt
Copy link

som-snytt commented Mar 27, 2023

scala/scala#10184 is the version bump

but why is it reading class files under --release?

at scala.tools.nsc.backend.jvm.opt.ByteCodeRepository.parseClass(ByteCodeRepository.scala:295)

at scala.tools.nsc.backend.jvm.analysis.BackendUtils.collectNestedClasses(BackendUtils.scala:422)
at scala.tools.nsc.backend.jvm.PostProcessor.setInnerClasses(PostProcessor.scala:136)

PARSE CLASS(java.lang.invoke.MethodHandles$Lookup)  // bit of debug
PARSE CLASS(java.lang.invoke.MethodHandles)

The successful compile outputs

1: invokedynamic #27,  0             // InvokeDynamic #0:makeConcatWithConstants:(Ljava/lang/String;)Ljava/lang/String;

InnerClasses:
  public static final #13= #10 of #12;    // Lookup=class java/lang/invoke/MethodHandles$Lookup of class java/lang/invoke/MethodHandles

This might have been a use case for --release:11 --target:8 except that does not work around it.

          // `StringConcatFactory` only got added in JDK 9, so use `StringBuilder` for lower
          if (classfileVersion.get < asm.Opcodes.V9) {

because brilliantly

def targetValue: String = releaseValue.getOrElse(target.value)

@SethTisue
Copy link
Member

nice catch, and good timing!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants