Fix unresolved symbol to SerialDescriptor in KSerializer if it was
referenced from user custom serializer code (kotlinx.serialization/290)
This commit is contained in:
+2
-1
@@ -65,7 +65,8 @@ abstract class SerializerCodegen(
|
|||||||
|
|
||||||
protected val generatedSerialDescPropertyDescriptor = getPropertyToGenerate(
|
protected val generatedSerialDescPropertyDescriptor = getPropertyToGenerate(
|
||||||
serializerDescriptor, SerialEntityNames.SERIAL_DESC_FIELD,
|
serializerDescriptor, SerialEntityNames.SERIAL_DESC_FIELD,
|
||||||
serializerDescriptor::checkSerializableClassPropertyResult)
|
serializerDescriptor::checkSerializableClassPropertyResult
|
||||||
|
)
|
||||||
protected val anySerialDescProperty = getProperty(
|
protected val anySerialDescProperty = getProperty(
|
||||||
serializerDescriptor, SerialEntityNames.SERIAL_DESC_FIELD,
|
serializerDescriptor, SerialEntityNames.SERIAL_DESC_FIELD,
|
||||||
serializerDescriptor::checkSerializableClassPropertyResult
|
serializerDescriptor::checkSerializableClassPropertyResult
|
||||||
|
|||||||
+4
-10
@@ -192,11 +192,6 @@ interface IrBuilderExtension {
|
|||||||
|
|
||||||
|
|
||||||
val SerializableProperty.irField: IrField get() = compilerContext.externalSymbols.referenceField(this.descriptor).owner
|
val SerializableProperty.irField: IrField get() = compilerContext.externalSymbols.referenceField(this.descriptor).owner
|
||||||
// get () {
|
|
||||||
// val symb = compilerContext.localSymbolTable.referenceField(this.descriptor)
|
|
||||||
// return if (symb.isBound) symb.owner
|
|
||||||
// else compilerContext.localSymbolTable.declareField()
|
|
||||||
// }
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
The rest of the file is mainly copied from FunctionGenerator.
|
The rest of the file is mainly copied from FunctionGenerator.
|
||||||
@@ -252,10 +247,10 @@ interface IrBuilderExtension {
|
|||||||
fieldSymbol: IrFieldSymbol,
|
fieldSymbol: IrFieldSymbol,
|
||||||
ownerSymbol: IrValueSymbol
|
ownerSymbol: IrValueSymbol
|
||||||
): IrSimpleFunction {
|
): IrSimpleFunction {
|
||||||
return compilerContext.localSymbolTable.declareSimpleFunctionWithOverrides(
|
// Declaration can also be called from user code. Since we lookup descriptor getter in externalSymbols
|
||||||
UNDEFINED_OFFSET, UNDEFINED_OFFSET,
|
// (see generateSave/generateLoad), seems it is correct approach to declare getter lazily there.
|
||||||
SERIALIZABLE_PLUGIN_ORIGIN, descriptor
|
val declaration = compilerContext.externalSymbols.referenceSimpleFunction(descriptor).owner
|
||||||
).buildWithScope { irAccessor ->
|
return declaration.buildWithScope { irAccessor ->
|
||||||
irAccessor.createParameterDeclarations((ownerSymbol as IrValueParameterSymbol).owner) // todo: neat this
|
irAccessor.createParameterDeclarations((ownerSymbol as IrValueParameterSymbol).owner) // todo: neat this
|
||||||
irAccessor.returnType = irAccessor.descriptor.returnType!!.toIrType()
|
irAccessor.returnType = irAccessor.descriptor.returnType!!.toIrType()
|
||||||
irAccessor.body = when (descriptor) {
|
irAccessor.body = when (descriptor) {
|
||||||
@@ -264,7 +259,6 @@ interface IrBuilderExtension {
|
|||||||
else -> throw AssertionError("Should be getter or setter: $descriptor")
|
else -> throw AssertionError("Should be getter or setter: $descriptor")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun generateDefaultGetterBody(
|
private fun generateDefaultGetterBody(
|
||||||
|
|||||||
+2
-2
@@ -167,7 +167,7 @@ class SerializerIrGenerator(val irClass: IrClass, override val compilerContext:
|
|||||||
val kOutputClass = serializerDescriptor.getClassFromSerializationPackage(STRUCTURE_ENCODER_CLASS)
|
val kOutputClass = serializerDescriptor.getClassFromSerializationPackage(STRUCTURE_ENCODER_CLASS)
|
||||||
val kOutputSmallClass = serializerDescriptor.getClassFromSerializationPackage(ENCODER_CLASS)
|
val kOutputSmallClass = serializerDescriptor.getClassFromSerializationPackage(ENCODER_CLASS)
|
||||||
|
|
||||||
val descriptorGetterSymbol = compilerContext.localSymbolTable.referenceFunction(anySerialDescProperty?.getter!!) //???
|
val descriptorGetterSymbol = compilerContext.externalSymbols.referenceFunction(anySerialDescProperty?.getter!!) //???
|
||||||
|
|
||||||
val localSerialDesc = irTemporary(irGet(descriptorGetterSymbol.owner.returnType, irThis(), descriptorGetterSymbol), "desc")
|
val localSerialDesc = irTemporary(irGet(descriptorGetterSymbol.owner.returnType, irThis(), descriptorGetterSymbol), "desc")
|
||||||
|
|
||||||
@@ -268,7 +268,7 @@ class SerializerIrGenerator(val irClass: IrClass, override val compilerContext:
|
|||||||
|
|
||||||
val inputClass = serializerDescriptor.getClassFromSerializationPackage(STRUCTURE_DECODER_CLASS)
|
val inputClass = serializerDescriptor.getClassFromSerializationPackage(STRUCTURE_DECODER_CLASS)
|
||||||
val inputSmallClass = serializerDescriptor.getClassFromSerializationPackage(DECODER_CLASS)
|
val inputSmallClass = serializerDescriptor.getClassFromSerializationPackage(DECODER_CLASS)
|
||||||
val descriptorGetterSymbol = compilerContext.localSymbolTable.referenceFunction(anySerialDescProperty?.getter!!) //???
|
val descriptorGetterSymbol = compilerContext.externalSymbols.referenceFunction(anySerialDescProperty?.getter!!) //???
|
||||||
val localSerialDesc = irTemporary(irGet(descriptorGetterSymbol.owner.returnType, irThis(), descriptorGetterSymbol), "desc")
|
val localSerialDesc = irTemporary(irGet(descriptorGetterSymbol.owner.returnType, irThis(), descriptorGetterSymbol), "desc")
|
||||||
|
|
||||||
// workaround due to unavailability of labels (KT-25386)
|
// workaround due to unavailability of labels (KT-25386)
|
||||||
|
|||||||
Reference in New Issue
Block a user