Add correct interpretation for unsigned arrays in vararg method handler

This commit is contained in:
Ivan Kylchik
2020-04-23 15:16:51 +03:00
parent 30f2affb93
commit 2e0d4c9af1
2 changed files with 19 additions and 2 deletions
@@ -648,7 +648,22 @@ class IrInterpreter(irModule: IrModuleFragment) {
else -> listOf(result)
}
}
stack.pushReturnValue(args.toPrimitiveStateArray(expression.type))
val array = when (expression.type.classifierOrFail.descriptor.name.asString()) {
"UByteArray", "UShortArray", "UIntArray", "ULongArray" -> {
val owner = expression.type.classOrNull!!.owner
val constructor = owner.primaryConstructor!!
val storageParameter = constructor.valueParameters.single()
val primitiveArray = args.map { ((it as Common).fields.single().state as Primitive<*>).value }
val unsignedArray = primitiveArray.toPrimitiveStateArray(storageParameter.type)
Common(owner).apply {
setSuperClassRecursive()
fields.add(Variable(storageParameter.descriptor, unsignedArray))
}
}
else -> args.toPrimitiveStateArray(expression.type)
}
stack.pushReturnValue(array)
return Next
}
@@ -193,7 +193,9 @@ object ArrayConstructor : IntrinsicBase() {
for (i in 0 until size) {
val indexVar = listOf(Variable(index.descriptor, i.toState(index.type)))
// TODO throw exception if label != RETURN
stack.newFrame(initPool = indexVar) { initLambda.irFunction.body!!.interpret() }.check(ReturnLabel.RETURN) { return it }
stack.newFrame(asSubFrame = initLambda.irFunction.isLocal || initLambda.irFunction.isInline, initPool = indexVar) {
initLambda.irFunction.body!!.interpret()
}.check(ReturnLabel.RETURN) { return it }
arrayValue[i] = stack.popReturnValue().let { (it as? Wrapper)?.value ?: (it as? Primitive<*>)?.value ?: it }
}
}