Skip to content

Commit 76071d2

Browse files
SethTisuetgodzik
authored andcommitted
classfile reader: allow JDK 9+ constant types in constant pool
forward-port of scala/scala#10675 and scala/scala#8595 references scala/bug#12396 and scala/bug#11635 fixes #19527 ("bad constant pool tag 17") also fixes unreported potential "bad constant pool tag 19" and "bad constant pool tag 20" errors
1 parent 99f2669 commit 76071d2

File tree

5 files changed

+31
-2
lines changed

5 files changed

+31
-2
lines changed

compiler/src/dotty/tools/dotc/core/classfile/ClassfileConstants.scala

+3
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,10 @@ object ClassfileConstants {
7373

7474
inline val CONSTANT_METHODHANDLE = 15
7575
inline val CONSTANT_METHODTYPE = 16
76+
inline val CONSTANT_DYNAMIC = 17
7677
inline val CONSTANT_INVOKEDYNAMIC = 18
78+
inline val CONSTANT_MODULE = 19
79+
inline val CONSTANT_PACKAGE = 20
7780

7881
// tags describing the type of a literal in attribute values
7982
inline val BYTE_TAG = 'B'

compiler/src/dotty/tools/dotc/core/classfile/ClassfileParser.scala

+3-2
Original file line numberDiff line numberDiff line change
@@ -1224,13 +1224,14 @@ class ClassfileParser(
12241224
(in.nextByte.toInt: @switch) match {
12251225
case CONSTANT_UTF8 | CONSTANT_UNICODE =>
12261226
in.skip(in.nextChar)
1227-
case CONSTANT_CLASS | CONSTANT_STRING | CONSTANT_METHODTYPE =>
1227+
case CONSTANT_CLASS | CONSTANT_STRING | CONSTANT_METHODTYPE
1228+
| CONSTANT_MODULE | CONSTANT_PACKAGE =>
12281229
in.skip(2)
12291230
case CONSTANT_METHODHANDLE =>
12301231
in.skip(3)
12311232
case CONSTANT_FIELDREF | CONSTANT_METHODREF | CONSTANT_INTFMETHODREF
12321233
| CONSTANT_NAMEANDTYPE | CONSTANT_INTEGER | CONSTANT_FLOAT
1233-
| CONSTANT_INVOKEDYNAMIC =>
1234+
| CONSTANT_INVOKEDYNAMIC | CONSTANT_DYNAMIC =>
12341235
in.skip(4)
12351236
case CONSTANT_LONG | CONSTANT_DOUBLE =>
12361237
in.skip(8)

compiler/test/dotty/tools/backend/jvm/ClassfileParserTest.scala

+3
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ class ClassfileParserTest {
3636
// in ClassfileConstants! that would defeat the purpose of the test
3737
"CONSTANT_CLASS",
3838
"CONSTANT_DOUBLE",
39+
"CONSTANT_DYNAMIC",
3940
"CONSTANT_FIELDREF",
4041
"CONSTANT_FLOAT",
4142
"CONSTANT_INTEGER",
@@ -45,7 +46,9 @@ class ClassfileParserTest {
4546
"CONSTANT_METHODHANDLE",
4647
"CONSTANT_METHODREF",
4748
"CONSTANT_METHODTYPE",
49+
"CONSTANT_MODULE",
4850
"CONSTANT_NAMEANDTYPE",
51+
"CONSTANT_PACKAGE",
4952
"CONSTANT_STRING",
5053
"CONSTANT_UNICODE",
5154
"CONSTANT_UTF8",

tests/pos/t12396/A_1.java

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// test: -jvm 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+
}

tests/pos/t12396/B_2.scala

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// test: -jvm 21+
2+
3+
class B {
4+
def bar = (new A_1).f(null)
5+
}

0 commit comments

Comments
 (0)