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,
|
||||
compilerContext.irBuiltIns.kClassClass.starProjectedType,
|
||||
classSymbol,
|
||||
classSymbol.starProjectedType
|
||||
classType.toIrType() // todo: maybe this is jvm-specific behavior
|
||||
)
|
||||
}
|
||||
|
||||
@@ -713,8 +713,7 @@ interface IrBuilderExtension {
|
||||
dispatchReceiverParameter: IrValueParameter,
|
||||
property: SerializableProperty
|
||||
): IrExpression? {
|
||||
val nullableSerializerFqn = getInternalPackageFqn(SpecialBuiltins.nullableSerializer)
|
||||
val nullableSerClass = compilerContext.referenceClass(nullableSerializerFqn) ?: error("Couldn't find class $nullableSerializerFqn")
|
||||
val nullableSerClass = compilerContext.referenceProperties(SerialEntityNames.wrapIntoNullableExt).single()
|
||||
val serializer =
|
||||
property.serializableWith?.toClassDescriptor
|
||||
?: if (!property.type.isTypeParameter()) generator.findTypeSerializerOrContext(
|
||||
@@ -736,24 +735,22 @@ interface IrBuilderExtension {
|
||||
private fun IrBuilderWithScope.wrapWithNullableSerializerIfNeeded(
|
||||
type: KotlinType,
|
||||
expression: IrExpression,
|
||||
nullableSerializerClass: IrClassSymbol
|
||||
): IrExpression {
|
||||
return if (type.isMarkedNullable) {
|
||||
val classDeclaration = nullableSerializerClass.owner
|
||||
val nullableConstructor = classDeclaration.declarations.first { it is IrConstructor } as IrConstructor
|
||||
val resultType = type.makeNotNullable()
|
||||
val typeParameters = classDeclaration.typeParameters
|
||||
val typeArguments = listOf(resultType.toIrType())
|
||||
irInvoke(
|
||||
null, nullableConstructor.symbol,
|
||||
typeArguments = typeArguments,
|
||||
valueArguments = listOf(expression),
|
||||
// Return type should be correctly substituted
|
||||
returnTypeHint = nullableConstructor.returnType.substitute(typeParameters, typeArguments)
|
||||
)
|
||||
} else {
|
||||
expression
|
||||
}
|
||||
nullableProp: IrPropertySymbol
|
||||
): IrExpression = if (type.isMarkedNullable) {
|
||||
val resultType = type.makeNotNullable()
|
||||
val typeArguments = listOf(resultType.toIrType())
|
||||
val callee = nullableProp.owner.getter!!
|
||||
|
||||
val returnType = callee.returnType.substitute(callee.typeParameters, typeArguments)
|
||||
|
||||
irInvoke(
|
||||
callee = callee.symbol,
|
||||
typeArguments = typeArguments,
|
||||
valueArguments = emptyList(),
|
||||
returnTypeHint = returnType
|
||||
).apply { extensionReceiver = expression }
|
||||
} else {
|
||||
expression
|
||||
}
|
||||
|
||||
|
||||
@@ -793,8 +790,7 @@ interface IrBuilderExtension {
|
||||
genericIndex: Int? = null,
|
||||
genericGetter: ((Int, KotlinType) -> IrExpression)? = null
|
||||
): IrExpression? {
|
||||
val nullableClassFqn = getInternalPackageFqn(SpecialBuiltins.nullableSerializer)
|
||||
val nullableSerClass = compilerContext.referenceClass(nullableClassFqn) ?: error("Expecting class $nullableClassFqn")
|
||||
val nullableSerClass = compilerContext.referenceProperties(SerialEntityNames.wrapIntoNullableExt).single()
|
||||
if (serializerClassOriginal == null) {
|
||||
if (genericIndex == null) return null
|
||||
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.
|
||||
*/
|
||||
|
||||
@@ -95,6 +95,8 @@ object SerialEntityNames {
|
||||
// parameters
|
||||
val dummyParamName = Name.identifier("serializationConstructorMarker")
|
||||
internal const val typeArgPrefix = "typeSerial"
|
||||
|
||||
internal val wrapIntoNullableExt = SerializationPackages.builtinsPackageFqName.child(Name.identifier("nullable"))
|
||||
}
|
||||
|
||||
object SpecialBuiltins {
|
||||
|
||||
Reference in New Issue
Block a user