diff --git a/compiler/ir/backend.jvm/lower/src/org/jetbrains/kotlin/backend/jvm/lower/MoveCompanionObjectFieldsLowering.kt b/compiler/ir/backend.jvm/lower/src/org/jetbrains/kotlin/backend/jvm/lower/MoveCompanionObjectFieldsLowering.kt index 85160aff583..96fa55d6ede 100644 --- a/compiler/ir/backend.jvm/lower/src/org/jetbrains/kotlin/backend/jvm/lower/MoveCompanionObjectFieldsLowering.kt +++ b/compiler/ir/backend.jvm/lower/src/org/jetbrains/kotlin/backend/jvm/lower/MoveCompanionObjectFieldsLowering.kt @@ -13,6 +13,7 @@ import org.jetbrains.kotlin.backend.jvm.ir.createJvmIrBuilder import org.jetbrains.kotlin.backend.jvm.ir.replaceThisByStaticReference import org.jetbrains.kotlin.backend.jvm.propertiesPhase import org.jetbrains.kotlin.descriptors.DescriptorVisibilities +import org.jetbrains.kotlin.ir.builders.declarations.addField import org.jetbrains.kotlin.ir.builders.declarations.addProperty import org.jetbrains.kotlin.ir.builders.declarations.buildField import org.jetbrains.kotlin.ir.builders.irCall @@ -106,33 +107,27 @@ private class MoveOrCopyCompanionObjectFieldsLowering(val context: JvmBackendCon } } - private fun copyConstProperty(oldProperty: IrProperty, newParent: IrClass): IrProperty = - newParent.addProperty() { - updateFrom(oldProperty) - name = oldProperty.name - isConst = true - }.also { property -> - val oldField = oldProperty.backingField!! - property.backingField = context.irFactory.buildField { - updateFrom(oldField) - name = oldField.name - isStatic = true - }.apply { - parent = newParent - correspondingPropertySymbol = property.symbol - annotations += oldField.annotations - initializer = oldField.initializer?.run { - IrExpressionBodyImpl(startOffset, endOffset, (expression as IrConst<*>).shallowCopy()) - } - - if (oldProperty.parentAsClass.visibility == DescriptorVisibilities.PRIVATE) { - context.createJvmIrBuilder(this.symbol).run { - annotations = filterOutAnnotations(DeprecationResolver.JAVA_DEPRECATED, annotations) + - irCall(irSymbols.javaLangDeprecatedConstructorWithDeprecatedFlag) - } + private fun copyConstProperty(oldProperty: IrProperty, newParent: IrClass): IrField { + val oldField = oldProperty.backingField!! + return newParent.addField { + updateFrom(oldField) + name = oldField.name + isStatic = true + }.apply { + parent = newParent + correspondingPropertySymbol = oldProperty.symbol + initializer = oldField.initializer?.run { + IrExpressionBodyImpl(startOffset, endOffset, (expression as IrConst<*>).shallowCopy()) + } + annotations += oldField.annotations + if (oldProperty.parentAsClass.visibility == DescriptorVisibilities.PRIVATE) { + context.createJvmIrBuilder(this.symbol).run { + annotations = filterOutAnnotations(DeprecationResolver.JAVA_DEPRECATED, annotations) + + irCall(irSymbols.javaLangDeprecatedConstructorWithDeprecatedFlag) } } } + } } private class RemapObjectFieldAccesses(val context: JvmBackendContext) : FileLoweringPass, IrElementTransformerVoid() { diff --git a/compiler/testData/codegen/bytecodeListing/deprecatedConstantPropertyInterfaceCompanion.kt b/compiler/testData/codegen/bytecodeListing/deprecatedConstantPropertyInterfaceCompanion.kt new file mode 100644 index 00000000000..2a646d089bc --- /dev/null +++ b/compiler/testData/codegen/bytecodeListing/deprecatedConstantPropertyInterfaceCompanion.kt @@ -0,0 +1,13 @@ +interface A { + companion object { + @Deprecated("no") + const val s = "yes" + } +} + +class B { + companion object { + @Deprecated("no") + const val s = "yes" + } +} \ No newline at end of file diff --git a/compiler/testData/codegen/bytecodeListing/deprecatedConstantPropertyInterfaceCompanion.txt b/compiler/testData/codegen/bytecodeListing/deprecatedConstantPropertyInterfaceCompanion.txt new file mode 100644 index 00000000000..1aadc394e05 --- /dev/null +++ b/compiler/testData/codegen/bytecodeListing/deprecatedConstantPropertyInterfaceCompanion.txt @@ -0,0 +1,38 @@ +@kotlin.Metadata +public final class A$Companion { + // source: 'deprecatedConstantPropertyInterfaceCompanion.kt' + synthetic final static field $$INSTANCE: A$Companion + public deprecated final static @org.jetbrains.annotations.NotNull field s: java.lang.String + static method (): void + private method (): void + public synthetic deprecated static @kotlin.Deprecated(message="no") method getS$annotations(): void + public final inner class A$Companion +} + +@kotlin.Metadata +public interface A { + // source: 'deprecatedConstantPropertyInterfaceCompanion.kt' + public final static @org.jetbrains.annotations.NotNull field Companion: A$Companion + public final static @kotlin.Deprecated(message="no") @org.jetbrains.annotations.NotNull field s: java.lang.String + static method (): void + public final inner class A$Companion +} + +@kotlin.Metadata +public final class B$Companion { + // source: 'deprecatedConstantPropertyInterfaceCompanion.kt' + private method (): void + public synthetic method (p0: kotlin.jvm.internal.DefaultConstructorMarker): void + public synthetic deprecated static @kotlin.Deprecated(message="no") method getS$annotations(): void + public final inner class B$Companion +} + +@kotlin.Metadata +public final class B { + // source: 'deprecatedConstantPropertyInterfaceCompanion.kt' + public final static @org.jetbrains.annotations.NotNull field Companion: B$Companion + public deprecated final static @org.jetbrains.annotations.NotNull field s: java.lang.String + static method (): void + public method (): void + public final inner class B$Companion +} diff --git a/compiler/testData/codegen/bytecodeListing/deprecatedConstantPropertyInterfaceCompanion_ir.txt b/compiler/testData/codegen/bytecodeListing/deprecatedConstantPropertyInterfaceCompanion_ir.txt new file mode 100644 index 00000000000..5cbd3463088 --- /dev/null +++ b/compiler/testData/codegen/bytecodeListing/deprecatedConstantPropertyInterfaceCompanion_ir.txt @@ -0,0 +1,38 @@ +@kotlin.Metadata +public final class A$Companion { + // source: 'deprecatedConstantPropertyInterfaceCompanion.kt' + synthetic final static field $$INSTANCE: A$Companion + public deprecated final static @org.jetbrains.annotations.NotNull field s: java.lang.String + static method (): void + private method (): void + public synthetic deprecated static @kotlin.Deprecated(message="no") method getS$annotations(): void + public final inner class A$Companion +} + +@kotlin.Metadata +public interface A { + // source: 'deprecatedConstantPropertyInterfaceCompanion.kt' + public final static @org.jetbrains.annotations.NotNull field Companion: A$Companion + public deprecated final static @org.jetbrains.annotations.NotNull field s: java.lang.String + static method (): void + public final inner class A$Companion +} + +@kotlin.Metadata +public final class B$Companion { + // source: 'deprecatedConstantPropertyInterfaceCompanion.kt' + private method (): void + public synthetic method (p0: kotlin.jvm.internal.DefaultConstructorMarker): void + public synthetic deprecated static @kotlin.Deprecated(message="no") method getS$annotations(): void + public final inner class B$Companion +} + +@kotlin.Metadata +public final class B { + // source: 'deprecatedConstantPropertyInterfaceCompanion.kt' + public final static @org.jetbrains.annotations.NotNull field Companion: B$Companion + public deprecated final static @org.jetbrains.annotations.NotNull field s: java.lang.String + static method (): void + public method (): void + public final inner class B$Companion +} diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BytecodeListingTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BytecodeListingTestGenerated.java index 4dae09801fc..e537a14fda3 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BytecodeListingTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BytecodeListingTestGenerated.java @@ -97,6 +97,12 @@ public class BytecodeListingTestGenerated extends AbstractBytecodeListingTest { runTest("compiler/testData/codegen/bytecodeListing/delegationToJavaInterfaceWithWildcardType.kt"); } + @Test + @TestMetadata("deprecatedConstantPropertyInterfaceCompanion.kt") + public void testDeprecatedConstantPropertyInterfaceCompanion() throws Exception { + runTest("compiler/testData/codegen/bytecodeListing/deprecatedConstantPropertyInterfaceCompanion.kt"); + } + @Test @TestMetadata("deserializeLambdaMethod.kt") public void testDeserializeLambdaMethod() throws Exception { diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBytecodeListingTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBytecodeListingTestGenerated.java index 7799a4e6797..989dd298ca0 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBytecodeListingTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBytecodeListingTestGenerated.java @@ -97,6 +97,12 @@ public class IrBytecodeListingTestGenerated extends AbstractIrBytecodeListingTes runTest("compiler/testData/codegen/bytecodeListing/delegationToJavaInterfaceWithWildcardType.kt"); } + @Test + @TestMetadata("deprecatedConstantPropertyInterfaceCompanion.kt") + public void testDeprecatedConstantPropertyInterfaceCompanion() throws Exception { + runTest("compiler/testData/codegen/bytecodeListing/deprecatedConstantPropertyInterfaceCompanion.kt"); + } + @Test @TestMetadata("deserializeLambdaMethod.kt") public void testDeserializeLambdaMethod() throws Exception {