From 5212ae6bbde38c47262b4543ccf4de8f8d50f3b0 Mon Sep 17 00:00:00 2001 From: Alexander Udalov Date: Fri, 13 Nov 2020 19:17:14 +0100 Subject: [PATCH] JVM IR: keep property annotations for inline class replacements In particular, `@Deprecated` is not lost anymore and accessors of deprecated property are generated with ACC_DEPRECATED just as in the old backend. #KT-43327 Fixed --- .../inlineclasses/MemoizedInlineClassReplacements.kt | 3 ++- .../deprecated/inlineClassTypesInSignature.kt | 9 +++++++++ .../deprecated/inlineClassTypesInSignature.txt | 11 +++++++++++ .../kotlin/codegen/BytecodeListingTestGenerated.java | 5 +++++ .../codegen/ir/IrBytecodeListingTestGenerated.java | 5 +++++ 5 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 compiler/testData/codegen/bytecodeListing/deprecated/inlineClassTypesInSignature.kt create mode 100644 compiler/testData/codegen/bytecodeListing/deprecated/inlineClassTypesInSignature.txt diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/inlineclasses/MemoizedInlineClassReplacements.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/inlineclasses/MemoizedInlineClassReplacements.kt index 469cf1e0994..1625006c782 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/inlineclasses/MemoizedInlineClassReplacements.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/inlineclasses/MemoizedInlineClassReplacements.kt @@ -219,7 +219,7 @@ class MemoizedInlineClassReplacements(private val mangleReturnTypes: Boolean, pr returnType = function.returnType }.apply { parent = function.parent - annotations += function.annotations + annotations = function.annotations copyTypeParameters(function.allTypeParameters) if (function.metadata != null) { metadata = function.metadata @@ -237,6 +237,7 @@ class MemoizedInlineClassReplacements(private val mangleReturnTypes: Boolean, pr }.apply { parent = propertySymbol.owner.parent copyAttributes(propertySymbol.owner) + annotations = propertySymbol.owner.annotations } } correspondingPropertySymbol = property.symbol diff --git a/compiler/testData/codegen/bytecodeListing/deprecated/inlineClassTypesInSignature.kt b/compiler/testData/codegen/bytecodeListing/deprecated/inlineClassTypesInSignature.kt new file mode 100644 index 00000000000..8c4f99a3631 --- /dev/null +++ b/compiler/testData/codegen/bytecodeListing/deprecated/inlineClassTypesInSignature.kt @@ -0,0 +1,9 @@ +// WITH_RUNTIME + +abstract class A { + @Deprecated("") + abstract var warn: UByte + + @Deprecated("", level = DeprecationLevel.HIDDEN) + abstract var hidden: UByte +} diff --git a/compiler/testData/codegen/bytecodeListing/deprecated/inlineClassTypesInSignature.txt b/compiler/testData/codegen/bytecodeListing/deprecated/inlineClassTypesInSignature.txt new file mode 100644 index 00000000000..e95a23985ff --- /dev/null +++ b/compiler/testData/codegen/bytecodeListing/deprecated/inlineClassTypesInSignature.txt @@ -0,0 +1,11 @@ +@kotlin.Metadata +public abstract class A { + // source: 'inlineClassTypesInSignature.kt' + public method (): void + public synthetic deprecated static @kotlin.Deprecated method getHidden-w2LRezQ$annotations(): void + public synthetic deprecated abstract method getHidden-w2LRezQ(): byte + public synthetic deprecated static @kotlin.Deprecated method getWarn-w2LRezQ$annotations(): void + public deprecated abstract method getWarn-w2LRezQ(): byte + public synthetic deprecated abstract method setHidden-7apg3OU(p0: byte): void + public deprecated abstract method setWarn-7apg3OU(p0: byte): void +} diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BytecodeListingTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BytecodeListingTestGenerated.java index c9a948b528b..80b23465eb5 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BytecodeListingTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BytecodeListingTestGenerated.java @@ -782,6 +782,11 @@ public class BytecodeListingTestGenerated extends AbstractBytecodeListingTest { public void testHidden() throws Exception { runTest("compiler/testData/codegen/bytecodeListing/deprecated/hidden.kt"); } + + @TestMetadata("inlineClassTypesInSignature.kt") + public void testInlineClassTypesInSignature() throws Exception { + runTest("compiler/testData/codegen/bytecodeListing/deprecated/inlineClassTypesInSignature.kt"); + } } @TestMetadata("compiler/testData/codegen/bytecodeListing/inline") diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBytecodeListingTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBytecodeListingTestGenerated.java index 7a53947c3de..2c49cd00e69 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBytecodeListingTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBytecodeListingTestGenerated.java @@ -752,6 +752,11 @@ public class IrBytecodeListingTestGenerated extends AbstractIrBytecodeListingTes public void testHidden() throws Exception { runTest("compiler/testData/codegen/bytecodeListing/deprecated/hidden.kt"); } + + @TestMetadata("inlineClassTypesInSignature.kt") + public void testInlineClassTypesInSignature() throws Exception { + runTest("compiler/testData/codegen/bytecodeListing/deprecated/inlineClassTypesInSignature.kt"); + } } @TestMetadata("compiler/testData/codegen/bytecodeListing/inline")