Use .nullable extension instead of NullableSerializer() constructor
Use correct projection in createClassReference() so primitive-boxes arrays behave correctly on JVM
This commit is contained in:
+19
-23
@@ -633,7 +633,7 @@ interface IrBuilderExtension {
|
|||||||
endOffset,
|
endOffset,
|
||||||
compilerContext.irBuiltIns.kClassClass.starProjectedType,
|
compilerContext.irBuiltIns.kClassClass.starProjectedType,
|
||||||
classSymbol,
|
classSymbol,
|
||||||
classSymbol.starProjectedType
|
classType.toIrType() // todo: maybe this is jvm-specific behavior
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -713,8 +713,7 @@ interface IrBuilderExtension {
|
|||||||
dispatchReceiverParameter: IrValueParameter,
|
dispatchReceiverParameter: IrValueParameter,
|
||||||
property: SerializableProperty
|
property: SerializableProperty
|
||||||
): IrExpression? {
|
): IrExpression? {
|
||||||
val nullableSerializerFqn = getInternalPackageFqn(SpecialBuiltins.nullableSerializer)
|
val nullableSerClass = compilerContext.referenceProperties(SerialEntityNames.wrapIntoNullableExt).single()
|
||||||
val nullableSerClass = compilerContext.referenceClass(nullableSerializerFqn) ?: error("Couldn't find class $nullableSerializerFqn")
|
|
||||||
val serializer =
|
val serializer =
|
||||||
property.serializableWith?.toClassDescriptor
|
property.serializableWith?.toClassDescriptor
|
||||||
?: if (!property.type.isTypeParameter()) generator.findTypeSerializerOrContext(
|
?: if (!property.type.isTypeParameter()) generator.findTypeSerializerOrContext(
|
||||||
@@ -736,24 +735,22 @@ interface IrBuilderExtension {
|
|||||||
private fun IrBuilderWithScope.wrapWithNullableSerializerIfNeeded(
|
private fun IrBuilderWithScope.wrapWithNullableSerializerIfNeeded(
|
||||||
type: KotlinType,
|
type: KotlinType,
|
||||||
expression: IrExpression,
|
expression: IrExpression,
|
||||||
nullableSerializerClass: IrClassSymbol
|
nullableProp: IrPropertySymbol
|
||||||
): IrExpression {
|
): IrExpression = if (type.isMarkedNullable) {
|
||||||
return if (type.isMarkedNullable) {
|
val resultType = type.makeNotNullable()
|
||||||
val classDeclaration = nullableSerializerClass.owner
|
val typeArguments = listOf(resultType.toIrType())
|
||||||
val nullableConstructor = classDeclaration.declarations.first { it is IrConstructor } as IrConstructor
|
val callee = nullableProp.owner.getter!!
|
||||||
val resultType = type.makeNotNullable()
|
|
||||||
val typeParameters = classDeclaration.typeParameters
|
val returnType = callee.returnType.substitute(callee.typeParameters, typeArguments)
|
||||||
val typeArguments = listOf(resultType.toIrType())
|
|
||||||
irInvoke(
|
irInvoke(
|
||||||
null, nullableConstructor.symbol,
|
callee = callee.symbol,
|
||||||
typeArguments = typeArguments,
|
typeArguments = typeArguments,
|
||||||
valueArguments = listOf(expression),
|
valueArguments = emptyList(),
|
||||||
// Return type should be correctly substituted
|
returnTypeHint = returnType
|
||||||
returnTypeHint = nullableConstructor.returnType.substitute(typeParameters, typeArguments)
|
).apply { extensionReceiver = expression }
|
||||||
)
|
} else {
|
||||||
} else {
|
expression
|
||||||
expression
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -793,8 +790,7 @@ interface IrBuilderExtension {
|
|||||||
genericIndex: Int? = null,
|
genericIndex: Int? = null,
|
||||||
genericGetter: ((Int, KotlinType) -> IrExpression)? = null
|
genericGetter: ((Int, KotlinType) -> IrExpression)? = null
|
||||||
): IrExpression? {
|
): IrExpression? {
|
||||||
val nullableClassFqn = getInternalPackageFqn(SpecialBuiltins.nullableSerializer)
|
val nullableSerClass = compilerContext.referenceProperties(SerialEntityNames.wrapIntoNullableExt).single()
|
||||||
val nullableSerClass = compilerContext.referenceClass(nullableClassFqn) ?: error("Expecting class $nullableClassFqn")
|
|
||||||
if (serializerClassOriginal == null) {
|
if (serializerClassOriginal == null) {
|
||||||
if (genericIndex == null) return null
|
if (genericIndex == null) return null
|
||||||
return genericGetter?.invoke(genericIndex, kType)
|
return genericGetter?.invoke(genericIndex, kType)
|
||||||
|
|||||||
+3
-1
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -95,6 +95,8 @@ object SerialEntityNames {
|
|||||||
// parameters
|
// parameters
|
||||||
val dummyParamName = Name.identifier("serializationConstructorMarker")
|
val dummyParamName = Name.identifier("serializationConstructorMarker")
|
||||||
internal const val typeArgPrefix = "typeSerial"
|
internal const val typeArgPrefix = "typeSerial"
|
||||||
|
|
||||||
|
internal val wrapIntoNullableExt = SerializationPackages.builtinsPackageFqName.child(Name.identifier("nullable"))
|
||||||
}
|
}
|
||||||
|
|
||||||
object SpecialBuiltins {
|
object SpecialBuiltins {
|
||||||
|
|||||||
Reference in New Issue
Block a user