diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/syntheticAccessorUtil.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/syntheticAccessorUtil.kt index f86d44b8f270f0b49c886e6ee872293a65029d56..4d7a8b1b30e0e89e13cb2b8e0963a4ee3827accc 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/syntheticAccessorUtil.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/syntheticAccessorUtil.kt @@ -17,6 +17,7 @@ package org.jetbrains.kotlin.codegen import org.jetbrains.kotlin.descriptors.* +import org.jetbrains.kotlin.resolve.DescriptorUtils enum class FieldAccessorKind(val suffix: String) { NORMAL("p"), @@ -26,15 +27,18 @@ enum class FieldAccessorKind(val suffix: String) { override fun toString() = suffix } +private fun CallableMemberDescriptor.getJvmName() = + DescriptorUtils.getJvmName(this) ?: name.asString() + fun getAccessorNameSuffix(descriptor: CallableMemberDescriptor, superCallDescriptor: ClassDescriptor?, accessorKind: FieldAccessorKind): String { val suffix = when (descriptor) { is ConstructorDescriptor -> return "will be ignored" is SimpleFunctionDescriptor -> - descriptor.name.asString() + descriptor.getJvmName() is PropertyDescriptor -> - descriptor.name.asString() + "$" + accessorKind + descriptor.getJvmName() + "$" + accessorKind else -> throw UnsupportedOperationException("Do not know how to create accessor for descriptor " + descriptor) } diff --git a/compiler/testData/codegen/box/syntheticAccessors/jvmNameForAccessors.kt b/compiler/testData/codegen/box/syntheticAccessors/jvmNameForAccessors.kt new file mode 100644 index 0000000000000000000000000000000000000000..0a39d77e650c24e0ad97cff457995fffe20f3949 --- /dev/null +++ b/compiler/testData/codegen/box/syntheticAccessors/jvmNameForAccessors.kt @@ -0,0 +1,15 @@ +// IGNORE_BACKEND: JS, NATIVE +// WITH_RUNTIME + + +@JvmName("fooA") +private fun String.foo(t: String?): String = this + +private fun String.foo(t: String): String = this + +fun runNoInline(fn: () -> String) = fn() + +fun box() = + runNoInline { "O".foo("") } + + runNoInline { "K".foo(null) } + diff --git a/compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java b/compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java index 74727ea1751229802acdb84916f052af37fac22e..158dd06bcea4d4cd32fcb38c834c7f7e2d2090f1 100644 --- a/compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java +++ b/compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java @@ -18029,6 +18029,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/syntheticAccessors"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JVM, true); } + @TestMetadata("jvmNameForAccessors.kt") + public void testJvmNameForAccessors() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/syntheticAccessors/jvmNameForAccessors.kt"); + doTest(fileName); + } + @TestMetadata("kt10047.kt") public void testKt10047() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/syntheticAccessors/kt10047.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java index 4619f4eb2cfe711e3ed6b9dddbd8d2b15fb27951..416c341a0e73153686f1fa0e81c93a5174e3656c 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java @@ -18029,6 +18029,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/syntheticAccessors"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JVM, true); } + @TestMetadata("jvmNameForAccessors.kt") + public void testJvmNameForAccessors() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/syntheticAccessors/jvmNameForAccessors.kt"); + doTest(fileName); + } + @TestMetadata("kt10047.kt") public void testKt10047() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/syntheticAccessors/kt10047.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java index 7d09abf41b5b2564d140723f070145a7f29cb990..74e3679a536534f7b990fc0f69f6c70c78d8456a 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java @@ -18029,6 +18029,12 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/syntheticAccessors"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JVM, true); } + @TestMetadata("jvmNameForAccessors.kt") + public void testJvmNameForAccessors() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/syntheticAccessors/jvmNameForAccessors.kt"); + doTest(fileName); + } + @TestMetadata("kt10047.kt") public void testKt10047() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/syntheticAccessors/kt10047.kt"); diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java index cbc136fb267ac174225c7d1241d6bac85480b85b..31dffb82384c1a7b064be9baf85e2f6b44be52e2 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java @@ -22103,6 +22103,18 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest { KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/syntheticAccessors"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JS, true); } + @TestMetadata("jvmNameForAccessors.kt") + public void testJvmNameForAccessors() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/syntheticAccessors/jvmNameForAccessors.kt"); + try { + doTest(fileName); + } + catch (Throwable ignore) { + return; + } + throw new AssertionError("Looks like this test can be unmuted. Remove IGNORE_BACKEND directive for that."); + } + @TestMetadata("kt10047.kt") public void testKt10047() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/syntheticAccessors/kt10047.kt");