diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/MethodSignatureMapper.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/MethodSignatureMapper.kt index 280d1485e97..d700d6349fc 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/MethodSignatureMapper.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/MethodSignatureMapper.kt @@ -92,22 +92,7 @@ class MethodSignatureMapper(private val context: JvmBackendContext) { return mangleMemberNameIfRequired(accessorName, function) } - val functionName = workaroundPropertyAccessorName(function) ?: function.name.asString() - return mangleMemberNameIfRequired(functionName, function) - } - - // This is a dirty hack which is needed to correctly map names of property accessors whose correspondingPropertySymbol was lost. - // The reason it's needed is that it sometimes gets lost during DeepCopyIrTreeWithSymbols because that algorithm doesn't copy - // the link to the property when transforming a simple function. This can be fixed but might require a lot of changes in backends, - // and will likely be unneeded as soon as we have proper properties in the IR (IrProperty which is a declaration parent). - // TODO: remove this hack as soon as IrProperty is a declaration parent - private fun workaroundPropertyAccessorName(function: IrFunction): String? { - val name = function.name.asString() - val ifGetter = name.removeSurrounding("") - if (ifGetter != name) return JvmAbi.getterName(ifGetter) - val ifSetter = name.removeSurrounding("") - if (ifSetter != name) return JvmAbi.setterName(ifSetter) - return null + return mangleMemberNameIfRequired(function.name.asString(), function) } private fun mangleMemberNameIfRequired(name: String, function: IrFunction): String { diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/BridgeLowering.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/BridgeLowering.kt index e8fc66c1d8c..34932981251 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/BridgeLowering.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/BridgeLowering.kt @@ -341,6 +341,14 @@ private class BridgeLowering(val context: JvmBackendContext) : FileLoweringPass, returnType = irFunction.returnType isFakeOverride = false }.apply { + // If the function is a property accessor, link in the new function as the new accessor for the property. + correspondingPropertySymbol = irFunction.correspondingPropertySymbol?.also { + if (irFunction.isGetter) { + it.owner.getter = this + } else { + it.owner.setter = this + } + } copyParametersWithErasure(this@addAbstractMethodStub, irFunction, needsArgumentBoxing) } diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/GenerateMultifileFacades.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/GenerateMultifileFacades.kt index 5d8b172a64f..e8e894c369f 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/GenerateMultifileFacades.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/GenerateMultifileFacades.kt @@ -41,6 +41,7 @@ import org.jetbrains.kotlin.ir.visitors.IrElementTransformer import org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid import org.jetbrains.kotlin.ir.visitors.transformChildrenVoid import org.jetbrains.kotlin.load.java.JavaVisibilities +import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.resolve.jvm.JvmClassName internal val generateMultifileFacadesPhase = namedIrModulePhase( @@ -217,7 +218,14 @@ private fun IrSimpleFunction.createMultifileDelegateIfNeeded( val function = buildFun { updateFrom(target) isFakeOverride = shouldGeneratePartHierarchy - name = target.name + name = if (shouldGeneratePartHierarchy) { + target.name + } else { + // Generating a bridge. If the bridge is targeting a property getter + // we need to take care to get the name right. The bridge is not a + // property getter itself. + Name.identifier(context.methodSignatureMapper.mapFunctionName(target)) + } } function.copyParameterDeclarationsFrom(target) diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/JvmStaticAnnotationLowering.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/JvmStaticAnnotationLowering.kt index 7665615362c..3084f6d2672 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/JvmStaticAnnotationLowering.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/JvmStaticAnnotationLowering.kt @@ -34,6 +34,7 @@ import org.jetbrains.kotlin.ir.expressions.impl.IrTypeOperatorCallImpl import org.jetbrains.kotlin.ir.util.* import org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid import org.jetbrains.kotlin.ir.visitors.transformChildrenVoid +import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.resolve.annotations.JVM_STATIC_ANNOTATION_FQ_NAME internal val jvmStaticAnnotationPhase = makeIrFilePhase( @@ -92,7 +93,10 @@ private class CompanionObjectJvmStaticLowering(val context: JvmBackendContext) : addFunction { returnType = target.returnType origin = JvmLoweredDeclarationOrigin.JVM_STATIC_WRAPPER - name = target.name + // The proxy needs to have the same name as what it is targeting. If that is a property accessor, + // we need to make sure that the name is mapped correctly. The static method is not a property accessor, + // so we do not have a property to link it up to. Therefore, we compute the right name now. + name = Name.identifier(context.methodSignatureMapper.mapFunctionName(target)) modality = if (isInterface) Modality.OPEN else target.modality visibility = target.visibility isSuspend = target.isSuspend diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/DeepCopyIrTreeWithSymbols.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/DeepCopyIrTreeWithSymbols.kt index 1fe5ece4ff9..ecd80a4954e 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/DeepCopyIrTreeWithSymbols.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/DeepCopyIrTreeWithSymbols.kt @@ -221,10 +221,13 @@ open class DeepCopyIrTreeWithSymbols( isExternal = declaration.isExternal ).apply { transformAnnotations(declaration) - this.backingField = declaration.backingField?.transform() - this.getter = declaration.getter?.transform() - this.setter = declaration.setter?.transform() - this.backingField?.let { + this.backingField = declaration.backingField?.transform()?.also { + it.correspondingPropertySymbol = symbol + } + this.getter = declaration.getter?.transform()?.also { + it.correspondingPropertySymbol = symbol + } + this.setter = declaration.setter?.transform()?.also { it.correspondingPropertySymbol = symbol } } diff --git a/compiler/testData/codegen/bytecodeText/builtinFunctions/size.kt b/compiler/testData/codegen/bytecodeText/builtinFunctions/size.kt index b0a7ce9b23c..dda5e3f62cb 100644 --- a/compiler/testData/codegen/bytecodeText/builtinFunctions/size.kt +++ b/compiler/testData/codegen/bytecodeText/builtinFunctions/size.kt @@ -53,10 +53,6 @@ fun box( c2.size } -/* - -*/ - // 8 public final bridge size\(\)I // 8 INVOKEVIRTUAL A[0-9]+\.size \(\)I // 1 INVOKEINTERFACE A9+\.size \(\)I