Coerce property value from correct type after retrieving it

#KT-25497 fixed
 Fixes https://github.com/Kotlin/kotlinx.serialization/issues/434
This commit is contained in:
Leonid Startsev
2019-05-22 17:28:43 +03:00
parent 9ce1f843e3
commit b5c4f3ecc8
2 changed files with 6 additions and 5 deletions
@@ -102,15 +102,15 @@ fun InstructionAdapter.genKOutputMethodCall(
val sti = generator.getSerialTypeInfo(property, propertyType)
val useSerializer = if (fromClassStartVar == null) stackValueSerializerInstanceFromSerializer(classCodegen, sti, generator)
else stackValueSerializerInstanceFromClass(classCodegen, sti, fromClassStartVar, generator)
if (!sti.unit) ImplementationBodyCodegen.genPropertyOnStack(
val actualType = if (!sti.unit) ImplementationBodyCodegen.genPropertyOnStack(
this,
expressionCodegen.context,
property.descriptor,
propertyOwnerType,
ownerVar,
classCodegen.state
)
StackValue.coerce(propertyType, sti.type, this)
) else null
actualType?.type?.let { type -> StackValue.coerce(type, sti.type, this) }
invokeinterface(
kOutputType.internalName,
CallingConventions.encode + sti.elementMethodPrefix + (if (useSerializer) "Serializable" else "") + CallingConventions.elementPostfix,
@@ -143,7 +143,8 @@ class SerializableCodegenImpl(
val writeLabel = Label()
val nonWriteLabel = Label()
// obj.prop != DEFAULT_VAL
ImplementationBodyCodegen.genPropertyOnStack(
val propAsmType = classCodegen.typeMapper.mapType(property.type)
val actualType: JvmKotlinType = ImplementationBodyCodegen.genPropertyOnStack(
this,
exprCodegen.context,
property.descriptor,
@@ -151,7 +152,7 @@ class SerializableCodegenImpl(
thisI,
classCodegen.state
)
val propAsmType = classCodegen.typeMapper.mapType(property.type)
StackValue.coerce(actualType.type, propAsmType, this)
val lhs = StackValue.onStack(propAsmType)
val (expr, _) = initializersMapper(property)
exprCodegen.gen(expr, propAsmType)