Skip to content

Commit 99f2669

Browse files
SethTisuelrytz
authored andcommitted
forward-port ClassfileParserTest from Scala 2
Co-authored-by: Lukas Rytz <[email protected]>
1 parent 7e92957 commit 99f2669

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package dotty.tools.backend.jvm
2+
3+
// painful to do Java reflection stuff without this
4+
import scala.language.unsafeNulls
5+
6+
import org.junit.Assert.assertEquals
7+
import org.junit.Test
8+
9+
import java.lang.reflect.Member
10+
11+
class ClassfileParserTest {
12+
@Test
13+
def noConstantPoolLag(): Unit = {
14+
def constNames(ms: List[Member]) = ms.collect {
15+
case f if f.getName.startsWith("CONSTANT_") => f.getName
16+
}.sorted
17+
18+
val toDotc = Map(
19+
"CONSTANT_INTERFACE_METHODREF" -> "CONSTANT_INTFMETHODREF",
20+
"CONSTANT_INVOKE_DYNAMIC" -> "CONSTANT_INVOKEDYNAMIC",
21+
"CONSTANT_METHOD_HANDLE" -> "CONSTANT_METHODHANDLE",
22+
"CONSTANT_METHOD_TYPE" -> "CONSTANT_METHODTYPE",
23+
"CONSTANT_NAME_AND_TYPE" -> "CONSTANT_NAMEANDTYPE",
24+
).withDefault(x => x)
25+
26+
val asmConsts = constNames(Class.forName("scala.tools.asm.Symbol").getDeclaredFields.toList)
27+
.map(_.stripSuffix("_TAG"))
28+
.map(toDotc)
29+
.::("CONSTANT_UNICODE")
30+
.sorted
31+
// in the Scala 2 version of this test, we also use Java reflection to get the constant
32+
// names out of ClassfileConstants. in Dotty, the constants are `inline val`s, invisible
33+
// to Java reflection, so we hardcode them here
34+
assertEquals(asmConsts, List(
35+
// do not add to this list without also making the corresponding change
36+
// in ClassfileConstants! that would defeat the purpose of the test
37+
"CONSTANT_CLASS",
38+
"CONSTANT_DOUBLE",
39+
"CONSTANT_FIELDREF",
40+
"CONSTANT_FLOAT",
41+
"CONSTANT_INTEGER",
42+
"CONSTANT_INTFMETHODREF",
43+
"CONSTANT_INVOKEDYNAMIC",
44+
"CONSTANT_LONG",
45+
"CONSTANT_METHODHANDLE",
46+
"CONSTANT_METHODREF",
47+
"CONSTANT_METHODTYPE",
48+
"CONSTANT_NAMEANDTYPE",
49+
"CONSTANT_STRING",
50+
"CONSTANT_UNICODE",
51+
"CONSTANT_UTF8",
52+
))
53+
}
54+
}

0 commit comments

Comments
 (0)