Coerce object types on return
This commit is contained in:
@@ -8,6 +8,7 @@ import org.objectweb.asm.Opcodes.*
|
|||||||
import org.objectweb.asm.tree.analysis.Interpreter
|
import org.objectweb.asm.tree.analysis.Interpreter
|
||||||
import org.objectweb.asm.tree.JumpInsnNode
|
import org.objectweb.asm.tree.JumpInsnNode
|
||||||
import org.objectweb.asm.tree.VarInsnNode
|
import org.objectweb.asm.tree.VarInsnNode
|
||||||
|
import org.objectweb.asm.util.Printer
|
||||||
|
|
||||||
trait InterpreterResult {
|
trait InterpreterResult {
|
||||||
fun toString(): String
|
fun toString(): String
|
||||||
@@ -97,8 +98,14 @@ fun interpreterLoop(
|
|||||||
IRETURN, LRETURN, FRETURN, DRETURN, ARETURN -> {
|
IRETURN, LRETURN, FRETURN, DRETURN, ARETURN -> {
|
||||||
val value = frame.getStack(0)!!
|
val value = frame.getStack(0)!!
|
||||||
val expectedType = Type.getReturnType(m.desc)
|
val expectedType = Type.getReturnType(m.desc)
|
||||||
if (value != NULL_VALUE && value.asmType != expectedType) {
|
if (expectedType.getSort() == Type.OBJECT) {
|
||||||
assert(insnOpcode == IRETURN, "Only ints should be coerced")
|
val coerced = if (value != NULL_VALUE && value.asmType != expectedType)
|
||||||
|
ObjectValue(value.obj, expectedType)
|
||||||
|
else value
|
||||||
|
return ValueReturned(coerced)
|
||||||
|
}
|
||||||
|
if (value.asmType != expectedType) {
|
||||||
|
assert(insnOpcode == IRETURN, "Only ints should be coerced: " + Printer.OPCODES[insnOpcode])
|
||||||
|
|
||||||
val coerced = when (expectedType.getSort()) {
|
val coerced = when (expectedType.getSort()) {
|
||||||
Type.BOOLEAN -> boolean(value.boolean)
|
Type.BOOLEAN -> boolean(value.boolean)
|
||||||
|
|||||||
@@ -44,6 +44,10 @@ class TestData {
|
|||||||
return "str";
|
return "str";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static Object returnStringAsObject() {
|
||||||
|
return "str";
|
||||||
|
}
|
||||||
|
|
||||||
static int variable() {
|
static int variable() {
|
||||||
int i = 153;
|
int i = 153;
|
||||||
return i;
|
return i;
|
||||||
|
|||||||
Reference in New Issue
Block a user