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 ffa08346bb0..08efc095a53 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 @@ -55,7 +55,7 @@ class JvmPropertiesLowering(private val context: JvmBackendContext) : IrElementT addIfNotNull(declaration.getter) addIfNotNull(declaration.setter) - if (declaration.annotations.isNotEmpty()) { + if (!declaration.isFakeOverride && declaration.annotations.isNotEmpty()) { add(createSyntheticMethodForAnnotations(declaration)) } } diff --git a/compiler/testData/codegen/bytecodeText/inheritedPropertyAnnotations.kt b/compiler/testData/codegen/bytecodeText/inheritedPropertyAnnotations.kt new file mode 100644 index 00000000000..c09fcbf2e87 --- /dev/null +++ b/compiler/testData/codegen/bytecodeText/inheritedPropertyAnnotations.kt @@ -0,0 +1,10 @@ +annotation class Ann + +abstract class Base { + @Ann val x: Int = 0 +} + +class Derived : Base() + +// We only want to generate the `getX$annotations` method in `Base`, not in `Derived`. +// 1 @LAnn;\(\) diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BytecodeTextTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BytecodeTextTestGenerated.java index f2b03872fee..8c6b4d2c78b 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BytecodeTextTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BytecodeTextTestGenerated.java @@ -119,6 +119,11 @@ public class BytecodeTextTestGenerated extends AbstractBytecodeTextTest { runTest("compiler/testData/codegen/bytecodeText/flagsInMultiFileInherit.kt"); } + @TestMetadata("inheritedPropertyAnnotations.kt") + public void testInheritedPropertyAnnotations() throws Exception { + runTest("compiler/testData/codegen/bytecodeText/inheritedPropertyAnnotations.kt"); + } + @TestMetadata("inlineFromOtherModule.kt") public void testInlineFromOtherModule() throws Exception { runTest("compiler/testData/codegen/bytecodeText/inlineFromOtherModule.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBytecodeTextTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBytecodeTextTestGenerated.java index f08b76cdee8..2cbca7415a2 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBytecodeTextTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBytecodeTextTestGenerated.java @@ -119,6 +119,11 @@ public class IrBytecodeTextTestGenerated extends AbstractIrBytecodeTextTest { runTest("compiler/testData/codegen/bytecodeText/flagsInMultiFileInherit.kt"); } + @TestMetadata("inheritedPropertyAnnotations.kt") + public void testInheritedPropertyAnnotations() throws Exception { + runTest("compiler/testData/codegen/bytecodeText/inheritedPropertyAnnotations.kt"); + } + @TestMetadata("inlineFromOtherModule.kt") public void testInlineFromOtherModule() throws Exception { runTest("compiler/testData/codegen/bytecodeText/inlineFromOtherModule.kt");