diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/irCodegenUtils.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/irCodegenUtils.kt index 6789e9a5fae..31eca3332a6 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/irCodegenUtils.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/irCodegenUtils.kt @@ -24,6 +24,8 @@ import org.jetbrains.kotlin.codegen.signature.BothSignatureWriter import org.jetbrains.kotlin.descriptors.* import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI import org.jetbrains.kotlin.ir.declarations.* +import org.jetbrains.kotlin.ir.expressions.IrCall +import org.jetbrains.kotlin.ir.expressions.IrExpressionBody import org.jetbrains.kotlin.ir.expressions.IrMemberAccessExpression import org.jetbrains.kotlin.ir.symbols.IrClassSymbol import org.jetbrains.kotlin.ir.symbols.IrSymbol @@ -356,7 +358,8 @@ val IrFunction.isSyntheticMethodForProperty: Boolean val IrFunction.isDeprecatedFunction: Boolean get() = isSyntheticMethodForProperty || isDeprecatedCallable || (this as? IrSimpleFunction)?.correspondingPropertySymbol?.owner?.isDeprecatedCallable == true || - isAccessorForDeprecatedPropertyImplementedByDelegation + isAccessorForDeprecatedPropertyImplementedByDelegation || + isAccessorForDeprecatedJvmStaticProperty private val IrFunction.isAccessorForDeprecatedPropertyImplementedByDelegation: Boolean get() = @@ -367,6 +370,18 @@ private val IrFunction.isAccessorForDeprecatedPropertyImplementedByDelegation: B it.owner.correspondingPropertySymbol?.owner?.isDeprecatedCallable == true } +private val IrFunction.isAccessorForDeprecatedJvmStaticProperty: Boolean + get() { + if (origin != JvmLoweredDeclarationOrigin.JVM_STATIC_WRAPPER) return false + val irExpressionBody = this.body as? IrExpressionBody + ?: throw AssertionError("IrExpressionBody expected for JvmStatic wrapper:\n${this.dump()}") + val irCall = irExpressionBody.expression as? IrCall + ?: throw AssertionError("IrCall expected inside JvmStatic wrapper:\n${this.dump()}") + val callee = irCall.symbol.owner + val property = callee.correspondingPropertySymbol?.owner ?: return false + return property.isDeprecatedCallable + } + @OptIn(ObsoleteDescriptorBasedAPI::class) val IrDeclaration.psiElement: PsiElement? get() = (descriptor as? DeclarationDescriptorWithSource)?.psiElement diff --git a/compiler/testData/codegen/bytecodeListing/deprecated/jvmStaticDeprecatedProperty.kt b/compiler/testData/codegen/bytecodeListing/deprecated/jvmStaticDeprecatedProperty.kt new file mode 100644 index 00000000000..cacca53f982 --- /dev/null +++ b/compiler/testData/codegen/bytecodeListing/deprecated/jvmStaticDeprecatedProperty.kt @@ -0,0 +1,24 @@ +// WITH_RUNTIME +// JVM_TARGET: 1.8 + +class TestClass { + companion object { + @Deprecated("") + @JvmStatic + val a: Int = 1 + } +} + +object TestObject { + @Deprecated("") + @JvmStatic + val a: Int = 1 +} + +interface TestInterface { + companion object { + @Deprecated("") + @JvmStatic + val a: Int = 1 + } +} \ No newline at end of file diff --git a/compiler/testData/codegen/bytecodeListing/deprecated/jvmStaticDeprecatedProperty.txt b/compiler/testData/codegen/bytecodeListing/deprecated/jvmStaticDeprecatedProperty.txt new file mode 100644 index 00000000000..81a84474400 --- /dev/null +++ b/compiler/testData/codegen/bytecodeListing/deprecated/jvmStaticDeprecatedProperty.txt @@ -0,0 +1,53 @@ +@kotlin.Metadata +public final class TestClass$Companion { + // source: 'jvmStaticDeprecatedProperty.kt' + private method (): void + public synthetic method (p0: kotlin.jvm.internal.DefaultConstructorMarker): void + public synthetic deprecated static @kotlin.Deprecated @kotlin.jvm.JvmStatic method getA$annotations(): void + public deprecated final method getA(): int + public final inner class TestClass$Companion +} + +@kotlin.Metadata +public final class TestClass { + // source: 'jvmStaticDeprecatedProperty.kt' + public final static @org.jetbrains.annotations.NotNull field Companion: TestClass$Companion + private deprecated final static field a: int + static method (): void + public method (): void + public synthetic final static method access$getA$cp(): int + public deprecated final static method getA(): int + public final inner class TestClass$Companion +} + +@kotlin.Metadata +public final class TestInterface$Companion { + // source: 'jvmStaticDeprecatedProperty.kt' + synthetic final static field $$INSTANCE: TestInterface$Companion + private deprecated final static field a: int + static method (): void + private method (): void + public synthetic deprecated static @kotlin.Deprecated @kotlin.jvm.JvmStatic method getA$annotations(): void + public deprecated final method getA(): int + public final inner class TestInterface$Companion +} + +@kotlin.Metadata +public interface TestInterface { + // source: 'jvmStaticDeprecatedProperty.kt' + public final static @org.jetbrains.annotations.NotNull field Companion: TestInterface$Companion + static method (): void + public deprecated static method getA(): int + public final inner class TestInterface$Companion +} + +@kotlin.Metadata +public final class TestObject { + // source: 'jvmStaticDeprecatedProperty.kt' + public final static @org.jetbrains.annotations.NotNull field INSTANCE: TestObject + private deprecated final static field a: int + static method (): void + private method (): void + public synthetic deprecated static @kotlin.Deprecated @kotlin.jvm.JvmStatic method getA$annotations(): void + public deprecated final static method getA(): int +} diff --git a/compiler/tests-gen/org/jetbrains/kotlin/codegen/BytecodeListingTestGenerated.java b/compiler/tests-gen/org/jetbrains/kotlin/codegen/BytecodeListingTestGenerated.java index c51b8439e0a..5fb50b0a9bd 100644 --- a/compiler/tests-gen/org/jetbrains/kotlin/codegen/BytecodeListingTestGenerated.java +++ b/compiler/tests-gen/org/jetbrains/kotlin/codegen/BytecodeListingTestGenerated.java @@ -827,6 +827,11 @@ public class BytecodeListingTestGenerated extends AbstractBytecodeListingTest { public void testInlineClassTypesInSignature() throws Exception { runTest("compiler/testData/codegen/bytecodeListing/deprecated/inlineClassTypesInSignature.kt"); } + + @TestMetadata("jvmStaticDeprecatedProperty.kt") + public void testJvmStaticDeprecatedProperty() throws Exception { + runTest("compiler/testData/codegen/bytecodeListing/deprecated/jvmStaticDeprecatedProperty.kt"); + } } @TestMetadata("compiler/testData/codegen/bytecodeListing/inline") diff --git a/compiler/tests-gen/org/jetbrains/kotlin/codegen/ir/IrBytecodeListingTestGenerated.java b/compiler/tests-gen/org/jetbrains/kotlin/codegen/ir/IrBytecodeListingTestGenerated.java index e2bdfb7564b..aad039f8b44 100644 --- a/compiler/tests-gen/org/jetbrains/kotlin/codegen/ir/IrBytecodeListingTestGenerated.java +++ b/compiler/tests-gen/org/jetbrains/kotlin/codegen/ir/IrBytecodeListingTestGenerated.java @@ -797,6 +797,11 @@ public class IrBytecodeListingTestGenerated extends AbstractIrBytecodeListingTes public void testInlineClassTypesInSignature() throws Exception { runTest("compiler/testData/codegen/bytecodeListing/deprecated/inlineClassTypesInSignature.kt"); } + + @TestMetadata("jvmStaticDeprecatedProperty.kt") + public void testJvmStaticDeprecatedProperty() throws Exception { + runTest("compiler/testData/codegen/bytecodeListing/deprecated/jvmStaticDeprecatedProperty.kt"); + } } @TestMetadata("compiler/testData/codegen/bytecodeListing/inline")