Skip to content

Commit afbad90

Browse files
authored
Merge pull request #10675 from SethTisue/issue-12936
Classfile reader: allow `CONSTANT_Dynamic` in constant pool
2 parents 6c0a9bc + 63a1976 commit afbad90

5 files changed

Lines changed: 55 additions & 1 deletion

File tree

src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ abstract class ClassfileParser(reader: ReusableInstance[ReusableDataReader]) {
212212
case CONSTANT_METHODHANDLE => in skip 3
213213
case CONSTANT_FIELDREF | CONSTANT_METHODREF | CONSTANT_INTFMETHODREF => in skip 4
214214
case CONSTANT_NAMEANDTYPE | CONSTANT_INTEGER | CONSTANT_FLOAT => in skip 4
215-
case CONSTANT_INVOKEDYNAMIC => in skip 4
215+
case CONSTANT_DYNAMIC | CONSTANT_INVOKEDYNAMIC => in skip 4
216216
case CONSTANT_LONG | CONSTANT_DOUBLE => in skip 8 ; i += 1
217217
case _ => errorBadTag(in.bp - 1)
218218
}

src/reflect/scala/reflect/internal/ClassfileConstants.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ object ClassfileConstants {
8181
final val CONSTANT_NAMEANDTYPE = 12
8282
final val CONSTANT_METHODHANDLE = 15
8383
final val CONSTANT_METHODTYPE = 16
84+
final val CONSTANT_DYNAMIC = 17
8485
final val CONSTANT_INVOKEDYNAMIC = 18
8586
final val CONSTANT_MODULE = 19
8687
final val CONSTANT_PACKAGE = 20

test/files/pos/t12396/A_1.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// javaVersion: 21+
2+
3+
public class A_1 {
4+
public int f(Object s) {
5+
switch(s) {
6+
case Res.R -> {
7+
return 1;
8+
}
9+
default -> {
10+
return 3;
11+
}
12+
}
13+
}
14+
static enum Res {
15+
R
16+
}
17+
}

test/files/pos/t12396/B_2.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// javaVersion: 21+
2+
3+
class B {
4+
def bar = (new A_1).f(null)
5+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package scala.tools.nsc.backend.jvm
2+
3+
import org.junit.Assert.assertEquals
4+
import org.junit.Test
5+
6+
import java.lang.reflect.Member
7+
8+
class ClassfileParserTest {
9+
@Test
10+
def noConstantPoolLag(): Unit = {
11+
def constNames(ms: List[Member]) = ms.collect {
12+
case f if f.getName.startsWith("CONSTANT_") => f.getName
13+
}.sorted
14+
15+
val toScalac = Map(
16+
"CONSTANT_INTERFACE_METHODREF" -> "CONSTANT_INTFMETHODREF",
17+
"CONSTANT_INVOKE_DYNAMIC" -> "CONSTANT_INVOKEDYNAMIC",
18+
"CONSTANT_METHOD_HANDLE" -> "CONSTANT_METHODHANDLE",
19+
"CONSTANT_METHOD_TYPE" -> "CONSTANT_METHODTYPE",
20+
"CONSTANT_NAME_AND_TYPE" -> "CONSTANT_NAMEANDTYPE",
21+
).withDefault(x => x)
22+
23+
val asmConsts = constNames(Class.forName("scala.tools.asm.Symbol").getDeclaredFields.toList)
24+
.map(_.stripSuffix("_TAG"))
25+
.map(toScalac)
26+
.::("CONSTANT_UNICODE")
27+
.sorted
28+
val scalacConsts = constNames(scala.reflect.internal.ClassfileConstants.getClass.getDeclaredMethods.toList)
29+
assertEquals(scalacConsts, asmConsts)
30+
}
31+
}

0 commit comments

Comments
 (0)