Export deserialization constructor from JS module
Fixes https://github.com/Kotlin/kotlinx.serialization/issues/443
This commit is contained in:
+2
-1
@@ -121,6 +121,7 @@ class SerializableJsTranslator(
|
|||||||
|
|
||||||
f.name = context.getInnerNameForDescriptor(constructorDescriptor)
|
f.name = context.getInnerNameForDescriptor(constructorDescriptor)
|
||||||
context.addDeclarationStatement(f.makeStmt())
|
context.addDeclarationStatement(f.makeStmt())
|
||||||
|
context.export(constructorDescriptor)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun JsBlockBuilder.generateSuperNonSerializableCall(superClass: ClassDescriptor, thisParameter: JsExpression) {
|
private fun JsBlockBuilder.generateSuperNonSerializableCall(superClass: ClassDescriptor, thisParameter: JsExpression) {
|
||||||
@@ -139,7 +140,7 @@ class SerializableJsTranslator(
|
|||||||
thisParameter: JsExpression,
|
thisParameter: JsExpression,
|
||||||
propertiesStart: Int
|
propertiesStart: Int
|
||||||
): Int {
|
): Int {
|
||||||
val constrDesc = KSerializerDescriptorResolver.createLoadConstructorDescriptor(superClass, context.bindingContext())
|
val constrDesc = superClass.constructors.single(ClassConstructorDescriptor::isSerializationCtor)
|
||||||
val constrRef = context.getInnerNameForDescriptor(constrDesc).makeRef()
|
val constrRef = context.getInnerNameForDescriptor(constrDesc).makeRef()
|
||||||
val superProperties = bindingContext.serializablePropertiesFor(superClass).serializableProperties
|
val superProperties = bindingContext.serializablePropertiesFor(superClass).serializableProperties
|
||||||
val superSlots = superProperties.bitMaskSlotCount()
|
val superSlots = superProperties.bitMaskSlotCount()
|
||||||
|
|||||||
+10
-2
@@ -13,13 +13,21 @@ import org.jetbrains.kotlin.name.FqName
|
|||||||
import org.jetbrains.kotlin.name.Name
|
import org.jetbrains.kotlin.name.Name
|
||||||
import org.jetbrains.kotlin.psi.ValueArgument
|
import org.jetbrains.kotlin.psi.ValueArgument
|
||||||
import org.jetbrains.kotlin.resolve.constants.KClassValue
|
import org.jetbrains.kotlin.resolve.constants.KClassValue
|
||||||
|
import org.jetbrains.kotlin.resolve.descriptorUtil.classId
|
||||||
import org.jetbrains.kotlin.resolve.descriptorUtil.module
|
import org.jetbrains.kotlin.resolve.descriptorUtil.module
|
||||||
import org.jetbrains.kotlin.resolve.lazy.descriptors.LazyAnnotationDescriptor
|
import org.jetbrains.kotlin.resolve.lazy.descriptors.LazyAnnotationDescriptor
|
||||||
import org.jetbrains.kotlin.types.KotlinType
|
import org.jetbrains.kotlin.types.KotlinType
|
||||||
import org.jetbrains.kotlin.types.KotlinTypeFactory
|
import org.jetbrains.kotlin.types.KotlinTypeFactory
|
||||||
|
|
||||||
internal fun ClassConstructorDescriptor.isSerializationCtor(): Boolean =
|
internal fun ClassConstructorDescriptor.isSerializationCtor(): Boolean {
|
||||||
kind == CallableMemberDescriptor.Kind.SYNTHESIZED && valueParameters.lastOrNull()?.name == SerialEntityNames.dummyParamName
|
/*kind == CallableMemberDescriptor.Kind.SYNTHESIZED does not work because DeserializedClassConstructorDescriptor loses its kind*/
|
||||||
|
return valueParameters.lastOrNull()?.run {
|
||||||
|
name == SerialEntityNames.dummyParamName && type.constructor.declarationDescriptor?.classId == ClassId(
|
||||||
|
SerializationPackages.packageFqName,
|
||||||
|
SerialEntityNames.SERIAL_CTOR_MARKER_NAME
|
||||||
|
)
|
||||||
|
} == true
|
||||||
|
}
|
||||||
|
|
||||||
// finds constructor (KSerializer<T0>, KSerializer<T1>...) on a KSerializer<T<T0, T1...>>
|
// finds constructor (KSerializer<T0>, KSerializer<T1>...) on a KSerializer<T<T0, T1...>>
|
||||||
internal fun findSerializerConstructorForTypeArgumentsSerializers(
|
internal fun findSerializerConstructorForTypeArgumentsSerializers(
|
||||||
|
|||||||
Reference in New Issue
Block a user