From 2b6a0d6c58d4c8ca3084bdb2b75068cf29171f79 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Steven=20Sch=C3=A4fer?= Date: Wed, 19 Feb 2020 15:16:16 +0100 Subject: [PATCH] JVM IR: Don't create $annotations stubs for fake overridden properties --- .../kotlin/backend/jvm/lower/JvmPropertiesLowering.kt | 2 +- .../bytecodeText/inheritedPropertyAnnotations.kt | 10 ++++++++++ .../kotlin/codegen/BytecodeTextTestGenerated.java | 5 +++++ .../kotlin/codegen/ir/IrBytecodeTextTestGenerated.java | 5 +++++ 4 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 compiler/testData/codegen/bytecodeText/inheritedPropertyAnnotations.kt 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");