From 5259af157af03ce70e91a4febea7af11ca82f7a4 Mon Sep 17 00:00:00 2001 From: Alexander Udalov Date: Tue, 27 Aug 2019 17:57:46 +0200 Subject: [PATCH] JVM IR: workaround correspondingPropertySymbol absence after deep copy --- .../jvm/codegen/MethodSignatureMapper.kt | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) 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 7cdd49902ec..6eee9b45b65 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 @@ -81,7 +81,22 @@ class MethodSignatureMapper(private val context: JvmBackendContext) { return mangleMemberNameIfRequired(accessorName, function) } - return mangleMemberNameIfRequired(function.name.asString(), 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 } private fun mangleMemberNameIfRequired(name: String, function: IrFunction): String {