[KxSerialization] Fix NPE when accessing delegated property
Kotlin 1.7.20 added optimizations for delegated properties on the JVM,
which broke serialization for optimized properties. Commit bfeff81
tried to fix that, but broke non-optimized delegated properties. This
commit restores correct serialization for optimized and non-optimized
properties, also ensuring that it only affects the JVM target.
#KT-58954 Fixed
#KT-59113 Fixed
This commit is contained in:
committed by
Alexander Udalov
parent
733ca5a358
commit
027593cd78
+6
-2
@@ -6,6 +6,7 @@
|
||||
package org.jetbrains.kotlinx.serialization.compiler.backend.ir
|
||||
|
||||
import org.jetbrains.kotlin.backend.common.lower.irThrow
|
||||
import org.jetbrains.kotlin.backend.jvm.lower.isJvmOptimizableDelegate
|
||||
import org.jetbrains.kotlin.descriptors.ClassKind
|
||||
import org.jetbrains.kotlin.descriptors.DescriptorVisibilities
|
||||
import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor
|
||||
@@ -21,6 +22,7 @@ import org.jetbrains.kotlin.ir.types.*
|
||||
import org.jetbrains.kotlin.ir.util.*
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.platform.jvm.isJvm
|
||||
import org.jetbrains.kotlin.util.OperatorNameConventions
|
||||
import org.jetbrains.kotlin.utils.getOrPutNullable
|
||||
import org.jetbrains.kotlinx.serialization.compiler.extensions.SerializationPluginContext
|
||||
@@ -82,8 +84,10 @@ class SerializableIrGenerator(
|
||||
it is IrProperty && it.backingField != null -> {
|
||||
if (it in serialDescs) {
|
||||
current = it
|
||||
} else if (it.backingField?.initializer != null && !it.isDelegated) {
|
||||
// skip transient lateinit or deferred properties (with null initializer)
|
||||
} else if (it.backingField?.initializer != null &&
|
||||
!(it.isJvmOptimizableDelegate() && compilerContext.platform.isJvm())
|
||||
) {
|
||||
// skip transient lateinit or deferred properties (with null initializer) and optimized delegations
|
||||
val expression = initializerAdapter(it.backingField!!.initializer!!)
|
||||
|
||||
statementsAfterSerializableProperty.getOrPutNullable(current, { mutableListOf() })
|
||||
|
||||
Reference in New Issue
Block a user