-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
classfile reader: handle JDK 9+ constant types in constant pool (#19533)
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
- Loading branch information
Showing
5 changed files
with
85 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
compiler/test/dotty/tools/backend/jvm/ClassfileParserTest.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package dotty.tools.backend.jvm | ||
|
||
// painful to do Java reflection stuff without this | ||
import scala.language.unsafeNulls | ||
|
||
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 toDotc = 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(toDotc) | ||
.::("CONSTANT_UNICODE") | ||
.sorted | ||
// in the Scala 2 version of this test, we also use Java reflection to get the constant | ||
// names out of ClassfileConstants. in Dotty, the constants are `inline val`s, invisible | ||
// to Java reflection, so we hardcode them here | ||
assertEquals(asmConsts, List( | ||
// do not add to this list without also making the corresponding change | ||
// in ClassfileConstants! that would defeat the purpose of the test | ||
"CONSTANT_CLASS", | ||
"CONSTANT_DOUBLE", | ||
"CONSTANT_DYNAMIC", | ||
"CONSTANT_FIELDREF", | ||
"CONSTANT_FLOAT", | ||
"CONSTANT_INTEGER", | ||
"CONSTANT_INTFMETHODREF", | ||
"CONSTANT_INVOKEDYNAMIC", | ||
"CONSTANT_LONG", | ||
"CONSTANT_METHODHANDLE", | ||
"CONSTANT_METHODREF", | ||
"CONSTANT_METHODTYPE", | ||
"CONSTANT_MODULE", | ||
"CONSTANT_NAMEANDTYPE", | ||
"CONSTANT_PACKAGE", | ||
"CONSTANT_STRING", | ||
"CONSTANT_UNICODE", | ||
"CONSTANT_UTF8", | ||
)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// test: -jvm 21+ | ||
|
||
public class A_1 { | ||
public int f(Object s) { | ||
switch(s) { | ||
case Res.R -> { | ||
return 1; | ||
} | ||
default -> { | ||
return 3; | ||
} | ||
} | ||
} | ||
static enum Res { | ||
R | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
// test: -jvm 21+ | ||
|
||
class B { | ||
def bar = (new A_1).f(null) | ||
} |