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

Support certain Java libraries compiled on JDK 21 #10675

Merged
merged 2 commits into from
Jan 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ abstract class ClassfileParser(reader: ReusableInstance[ReusableDataReader]) {
case CONSTANT_METHODHANDLE => in skip 3
case CONSTANT_FIELDREF | CONSTANT_METHODREF | CONSTANT_INTFMETHODREF => in skip 4
case CONSTANT_NAMEANDTYPE | CONSTANT_INTEGER | CONSTANT_FLOAT => in skip 4
case CONSTANT_INVOKEDYNAMIC => in skip 4
case CONSTANT_DYNAMIC | CONSTANT_INVOKEDYNAMIC => in skip 4
case CONSTANT_LONG | CONSTANT_DOUBLE => in skip 8 ; i += 1
case _ => errorBadTag(in.bp - 1)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ object ClassfileConstants {
final val CONSTANT_NAMEANDTYPE = 12
final val CONSTANT_METHODHANDLE = 15
final val CONSTANT_METHODTYPE = 16
final val CONSTANT_DYNAMIC = 17
final val CONSTANT_INVOKEDYNAMIC = 18
final val CONSTANT_MODULE = 19
final val CONSTANT_PACKAGE = 20
Expand Down
17 changes: 17 additions & 0 deletions test/files/pos/t12396/A_1.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// javaVersion: 21+

public class A_1 {
public int f(Object s) {
switch(s) {
case Res.R -> {
return 1;
}
default -> {
return 3;
}
}
}
static enum Res {
R
}
}
5 changes: 5 additions & 0 deletions test/files/pos/t12396/B_2.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// javaVersion: 21+

class B {
def bar = (new A_1).f(null)
}
31 changes: 31 additions & 0 deletions test/junit/scala/tools/nsc/backend/jvm/ClassfileParserTest.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package scala.tools.nsc.backend.jvm

import org.junit.Assert.assertEquals
import org.junit.Test

import java.lang.reflect.Member

class ClassfileParserTest {
@Test
def noConstantPoolLag(): Unit = {
def constNames(ms: List[Member]) = ms.collect {
case f if f.getName.startsWith("CONSTANT_") => f.getName
}.sorted

val toScalac = Map(
"CONSTANT_INTERFACE_METHODREF" -> "CONSTANT_INTFMETHODREF",
"CONSTANT_INVOKE_DYNAMIC" -> "CONSTANT_INVOKEDYNAMIC",
"CONSTANT_METHOD_HANDLE" -> "CONSTANT_METHODHANDLE",
"CONSTANT_METHOD_TYPE" -> "CONSTANT_METHODTYPE",
"CONSTANT_NAME_AND_TYPE" -> "CONSTANT_NAMEANDTYPE",
).withDefault(x => x)

val asmConsts = constNames(Class.forName("scala.tools.asm.Symbol").getDeclaredFields.toList)
.map(_.stripSuffix("_TAG"))
.map(toScalac)
.::("CONSTANT_UNICODE")
.sorted
val scalacConsts = constNames(scala.reflect.internal.ClassfileConstants.getClass.getDeclaredMethods.toList)
assertEquals(scalacConsts, asmConsts)
}
}