diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/DelegationLowering.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/DelegationLowering.kt index 8a01b32ec2a..8c57a62cd05 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/DelegationLowering.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/DelegationLowering.kt @@ -74,7 +74,9 @@ internal class PropertyDelegationLowering(val context: Context) : FileLoweringPa } override fun lower(irFile: IrFile) { - val kProperties = mutableMapOf>() + // Somehow there is no reasonable common ancestor for IrProperty and IrLocalDelegatedProperty, + // so index by IrDeclaration. + val kProperties = mutableMapOf>() val arrayClass = context.ir.symbols.array.owner @@ -121,7 +123,7 @@ internal class PropertyDelegationLowering(val context: Context) : FileLoweringPa 2 -> error("Callable reference to properties with two receivers is not allowed: ${expression.descriptor}") else -> { // Cache KProperties with no arguments. - val field = kProperties.getOrPut(expression.descriptor) { + val field = kProperties.getOrPut(expression.symbol.owner) { createKProperty(expression, this) to kProperties.size } @@ -141,16 +143,14 @@ internal class PropertyDelegationLowering(val context: Context) : FileLoweringPa val endOffset = expression.endOffset val irBuilder = context.createIrBuilder(currentScope!!.scope.scopeOwnerSymbol, startOffset, endOffset) irBuilder.run { - val propertyDescriptor = expression.descriptor - val receiversCount = listOf(expression.dispatchReceiver, expression.extensionReceiver).count { it != null } if (receiversCount == 2) - throw AssertionError("Callable reference to properties with two receivers is not allowed: $propertyDescriptor") + throw AssertionError("Callable reference to properties with two receivers is not allowed: ${expression}") else { // Cache KProperties with no arguments. // TODO: what about `receiversCount == 1` case? - val field = kProperties.getOrPut(propertyDescriptor) { + val field = kProperties.getOrPut(expression.symbol.owner) { createLocalKProperty( - propertyDescriptor, + expression.symbol.owner.name.asString(), expression.getter.owner.returnType, this ) to kProperties.size @@ -265,7 +265,7 @@ internal class PropertyDelegationLowering(val context: Context) : FileLoweringPa } } - private fun createLocalKProperty(propertyDescriptor: VariableDescriptorWithAccessors, + private fun createLocalKProperty(propertyName: String, propertyType: IrType, irBuilder: IrBuilderWithScope): IrExpression { irBuilder.run { @@ -275,7 +275,7 @@ internal class PropertyDelegationLowering(val context: Context) : FileLoweringPa isLocal = true, isMutable = false) val initializer = irCall(symbol.owner, constructorTypeArguments).apply { - putValueArgument(0, irString(propertyDescriptor.name.asString())) + putValueArgument(0, irString(propertyName)) putValueArgument(1, with(kTypeGenerator) { irKType(propertyType) }) } return initializer