JVM_IR KT-43524 static wrappers for deprecated accessors are deprecated

This commit is contained in:
Dmitry Petrov
2020-12-01 13:02:42 +03:00
parent e96fc74ffa
commit 1412ee96f8
5 changed files with 103 additions and 1 deletions
@@ -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
@@ -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
}
}
@@ -0,0 +1,53 @@
@kotlin.Metadata
public final class TestClass$Companion {
// source: 'jvmStaticDeprecatedProperty.kt'
private method <init>(): void
public synthetic method <init>(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 <clinit>(): void
public method <init>(): 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 <clinit>(): void
private method <init>(): 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 <clinit>(): 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 <clinit>(): void
private method <init>(): void
public synthetic deprecated static @kotlin.Deprecated @kotlin.jvm.JvmStatic method getA$annotations(): void
public deprecated final static method getA(): int
}
@@ -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")
@@ -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")