Do not attempt to get field initializer if it is not available.

This may happen on Native if the property is in another module.

#KT-62522 Fixed
Related to: KT-62523
This commit is contained in:
Leonid Startsev
2023-10-11 19:05:47 +02:00
committed by Space Team
parent 9c1fa93607
commit dcfc20f1ff
@@ -238,12 +238,13 @@ abstract class BaseIrGenerator(private val currentClass: IrClass, final override
// check for call to .shouldEncodeElementDefault
val encodeDefaults = property.ir.getEncodeDefaultAnnotationValue()
val field =
property.ir.backingField // Nullable when property from another module; can't compare it with default value on JS or Native
if (!property.optional || encodeDefaults == true || field == null) {
property.ir.backingField
val initializer = field?.initializer // FIXME: Null when property from another module; can't compare it with default value on JS or Native
if (!property.optional || encodeDefaults == true || field == null || initializer == null) {
// emit call right away
+elementCall
} else {
val partB = irNotEquals(property.irGet(), initializerAdapter(field.initializer!!))
val partB = irNotEquals(property.irGet(), initializerAdapter(initializer))
val condition = if (encodeDefaults == false) {
// drop default without call to .shouldEncodeElementDefault