diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/JvmPropertiesLowering.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/JvmPropertiesLowering.kt index 45a58966e09..9a92eaba3f0 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/JvmPropertiesLowering.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/JvmPropertiesLowering.kt @@ -12,6 +12,8 @@ import org.jetbrains.kotlin.backend.common.lower.createIrBuilder import org.jetbrains.kotlin.backend.jvm.JvmBackendContext import org.jetbrains.kotlin.backend.jvm.JvmLoweredDeclarationOrigin import org.jetbrains.kotlin.backend.jvm.ir.needsAccessor +import org.jetbrains.kotlin.backend.jvm.lower.inlineclasses.hasMangledReturnType +import org.jetbrains.kotlin.backend.jvm.lower.inlineclasses.requiresMangling import org.jetbrains.kotlin.config.LanguageFeature import org.jetbrains.kotlin.descriptors.ClassKind import org.jetbrains.kotlin.descriptors.Modality @@ -143,9 +145,17 @@ class JvmPropertiesLowering(private val backendContext: JvmBackendContext) : IrE private fun computeSyntheticMethodName(property: IrProperty): String { val baseName = if (backendContext.state.languageVersionSettings.supportsFeature(LanguageFeature.UseGetterNameForPropertyAnnotationsMethodOnJvm)) { - property.getter?.let { getter -> - backendContext.methodSignatureMapper.mapFunctionName(getter) - } ?: JvmAbi.getterName(property.name.asString()) + val getter = property.getter + if (getter != null) { + val needsMangling = + getter.extensionReceiverParameter?.type?.requiresMangling == true || + (backendContext.state.functionsWithInlineClassReturnTypesMangled && getter.hasMangledReturnType) + + backendContext.methodSignatureMapper.mapFunctionName( + if (needsMangling) backendContext.inlineClassReplacements.getReplacementFunction(getter) ?: getter + else getter + ) + } else JvmAbi.getterName(property.name.asString()) } else { property.name.asString() } diff --git a/compiler/testData/codegen/bytecodeListing/inlineClasses/annotatedPropertyWithInlineClassTypeInSignature.kt b/compiler/testData/codegen/bytecodeListing/inlineClasses/annotatedPropertyWithInlineClassTypeInSignature.kt new file mode 100644 index 00000000000..c008f02f0e9 --- /dev/null +++ b/compiler/testData/codegen/bytecodeListing/inlineClasses/annotatedPropertyWithInlineClassTypeInSignature.kt @@ -0,0 +1,20 @@ +inline class Z(val x: Int) { + @Anno + val member: Int get() = x +} + +annotation class Anno + +@Anno +val Z.topLevel: Int get() = 0 + +@Anno +val returnType: Z get() = Z(0) + +class C { + @Anno + val Z.memberExtension: Int get() = 0 + + @Anno + val returnType: Z get() = Z(0) +} diff --git a/compiler/testData/codegen/bytecodeListing/inlineClasses/annotatedPropertyWithInlineClassTypeInSignature.txt b/compiler/testData/codegen/bytecodeListing/inlineClasses/annotatedPropertyWithInlineClassTypeInSignature.txt new file mode 100644 index 00000000000..37c16108ad2 --- /dev/null +++ b/compiler/testData/codegen/bytecodeListing/inlineClasses/annotatedPropertyWithInlineClassTypeInSignature.txt @@ -0,0 +1,44 @@ +@java.lang.annotation.Retention +@kotlin.Metadata +public annotation class Anno { + // source: 'annotatedPropertyWithInlineClassTypeInSignature.kt' +} + +@kotlin.Metadata +public final class AnnotatedPropertyWithInlineClassTypeInSignatureKt { + // source: 'annotatedPropertyWithInlineClassTypeInSignature.kt' + public synthetic deprecated static @Anno method getReturnType$annotations(): void + public final static method getReturnType(): int + public synthetic deprecated static @Anno method getTopLevel-IQRRRT4$annotations(p0: int): void + public final static method getTopLevel-IQRRRT4(p0: int): int +} + +@kotlin.Metadata +public final class C { + // source: 'annotatedPropertyWithInlineClassTypeInSignature.kt' + public method (): void + public synthetic deprecated static @Anno method getMemberExtension-IQRRRT4$annotations(p0: int): void + public final method getMemberExtension-IQRRRT4(p0: int): int + public synthetic deprecated static @Anno method getReturnType-a_XrcN0$annotations(): void + public final method getReturnType-a_XrcN0(): int +} + +@kotlin.Metadata +public final class Z { + // source: 'annotatedPropertyWithInlineClassTypeInSignature.kt' + private final field x: int + private synthetic method (p0: int): void + public synthetic final static method box-impl(p0: int): Z + public static method constructor-impl(p0: int): int + public method equals(p0: java.lang.Object): boolean + public static method equals-impl(p0: int, p1: java.lang.Object): boolean + public final static method equals-impl0(p0: int, p1: int): boolean + public synthetic deprecated static @Anno method getMember$annotations(): void + public final static method getMember-impl(p0: int): int + public final method getX(): int + public method hashCode(): int + public static method hashCode-impl(p0: int): int + public method toString(): java.lang.String + public static method toString-impl(p0: int): java.lang.String + public synthetic final method unbox-impl(): int +} diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BytecodeListingTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BytecodeListingTestGenerated.java index 70599b657f8..fc7ae3cdc51 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BytecodeListingTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BytecodeListingTestGenerated.java @@ -807,6 +807,11 @@ public class BytecodeListingTestGenerated extends AbstractBytecodeListingTest { KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/bytecodeListing/inlineClasses"), Pattern.compile("^(.+)\\.kt$"), null, true); } + @TestMetadata("annotatedPropertyWithInlineClassTypeInSignature.kt") + public void testAnnotatedPropertyWithInlineClassTypeInSignature() throws Exception { + runTest("compiler/testData/codegen/bytecodeListing/inlineClasses/annotatedPropertyWithInlineClassTypeInSignature.kt"); + } + @TestMetadata("annotationsOnHiddenConstructor.kt") public void testAnnotationsOnHiddenConstructor() throws Exception { runTest("compiler/testData/codegen/bytecodeListing/inlineClasses/annotationsOnHiddenConstructor.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBytecodeListingTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBytecodeListingTestGenerated.java index a83c1f14338..b3934b4ec38 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBytecodeListingTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBytecodeListingTestGenerated.java @@ -777,6 +777,11 @@ public class IrBytecodeListingTestGenerated extends AbstractIrBytecodeListingTes KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/bytecodeListing/inlineClasses"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true); } + @TestMetadata("annotatedPropertyWithInlineClassTypeInSignature.kt") + public void testAnnotatedPropertyWithInlineClassTypeInSignature() throws Exception { + runTest("compiler/testData/codegen/bytecodeListing/inlineClasses/annotatedPropertyWithInlineClassTypeInSignature.kt"); + } + @TestMetadata("annotationsOnHiddenConstructor.kt") public void testAnnotationsOnHiddenConstructor() throws Exception { runTest("compiler/testData/codegen/bytecodeListing/inlineClasses/annotationsOnHiddenConstructor.kt");