JVM IR: copy corresponding property+annotations for DefaultImpls methods
Instead of using methodSignatureMapper which was an obsolete hack to make accessor names "getFoo" instead of "<get-foo>". In particular, this keeps the `@Deprecated` annotation on the corresponding property, which results in ACC_DEPRECATED in codegen. #KT-43326 Fixed
This commit is contained in:
@@ -35,7 +35,6 @@ import org.jetbrains.kotlin.ir.expressions.IrExpression
|
||||
import org.jetbrains.kotlin.ir.expressions.IrFunctionReference
|
||||
import org.jetbrains.kotlin.ir.symbols.*
|
||||
import org.jetbrains.kotlin.ir.types.IrType
|
||||
import org.jetbrains.kotlin.ir.util.IdSignature
|
||||
import org.jetbrains.kotlin.ir.util.SymbolTable
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.psi2ir.PsiErrorBuilder
|
||||
@@ -72,7 +71,7 @@ class JvmBackendContext(
|
||||
val methodSignatureMapper = MethodSignatureMapper(this)
|
||||
|
||||
internal val innerClassesSupport = JvmInnerClassesSupport(irFactory)
|
||||
internal val cachedDeclarations = JvmCachedDeclarations(this, methodSignatureMapper, state.languageVersionSettings)
|
||||
internal val cachedDeclarations = JvmCachedDeclarations(this, state.languageVersionSettings)
|
||||
|
||||
override val mapping: Mapping = DefaultMapping()
|
||||
|
||||
|
||||
+2
-4
@@ -8,7 +8,6 @@ package org.jetbrains.kotlin.backend.jvm
|
||||
import org.jetbrains.kotlin.backend.common.ir.copyParameterDeclarationsFrom
|
||||
import org.jetbrains.kotlin.backend.common.ir.createImplicitParameterDeclarationWithWrappedDescriptor
|
||||
import org.jetbrains.kotlin.backend.common.ir.createStaticFunctionWithReceivers
|
||||
import org.jetbrains.kotlin.backend.jvm.codegen.MethodSignatureMapper
|
||||
import org.jetbrains.kotlin.backend.jvm.codegen.isJvmInterface
|
||||
import org.jetbrains.kotlin.backend.jvm.ir.copyCorrespondingPropertyFrom
|
||||
import org.jetbrains.kotlin.backend.jvm.ir.createJvmIrBuilder
|
||||
@@ -34,7 +33,6 @@ import org.jetbrains.kotlin.resolve.deprecation.DeprecationResolver
|
||||
|
||||
class JvmCachedDeclarations(
|
||||
private val context: JvmBackendContext,
|
||||
private val methodSignatureMapper: MethodSignatureMapper,
|
||||
private val languageVersionSettings: LanguageVersionSettings
|
||||
) {
|
||||
private val singletonFieldDeclarations = HashMap<IrSymbolOwner, IrField>()
|
||||
@@ -152,9 +150,8 @@ class JvmCachedDeclarations(
|
||||
return defaultImplsMethods.getOrPut(interfaceFun) {
|
||||
val defaultImpls = getDefaultImplsClass(interfaceFun.parentAsClass)
|
||||
|
||||
val name = Name.identifier(methodSignatureMapper.mapFunctionName(interfaceFun))
|
||||
context.irFactory.createStaticFunctionWithReceivers(
|
||||
defaultImpls, name, interfaceFun,
|
||||
defaultImpls, interfaceFun.name, interfaceFun,
|
||||
dispatchReceiverType = parent.defaultType,
|
||||
// If `interfaceFun` is not a real implementation, then we're generating stubs in a descendant
|
||||
// interface's DefaultImpls. For example,
|
||||
@@ -189,6 +186,7 @@ class JvmCachedDeclarations(
|
||||
isFakeOverride = false,
|
||||
typeParametersFromContext = parent.typeParameters
|
||||
).also {
|
||||
it.copyCorrespondingPropertyFrom(interfaceFun)
|
||||
if (it.origin == JvmLoweredDeclarationOrigin.DEFAULT_IMPLS_BRIDGE_FOR_COMPATIBILITY &&
|
||||
!it.annotations.hasAnnotation(DeprecationResolver.JAVA_DEPRECATED)
|
||||
) {
|
||||
|
||||
@@ -319,11 +319,12 @@ fun IrSimpleFunction.copyCorrespondingPropertyFrom(source: IrSimpleFunction) {
|
||||
val property = source.correspondingPropertySymbol?.owner ?: return
|
||||
val target = this
|
||||
|
||||
correspondingPropertySymbol = factory.buildProperty() {
|
||||
correspondingPropertySymbol = factory.buildProperty {
|
||||
name = property.name
|
||||
updateFrom(property)
|
||||
}.apply {
|
||||
parent = target.parent
|
||||
annotations = property.annotations
|
||||
when {
|
||||
source.isGetter -> getter = target
|
||||
source.isSetter -> setter = target
|
||||
|
||||
@@ -51,3 +51,8 @@ var <T> List<T>.textGenExtVar
|
||||
get() = 1
|
||||
set(v) {}
|
||||
|
||||
interface I {
|
||||
@Deprecated("")
|
||||
val <T> T.id: T
|
||||
get() = this
|
||||
}
|
||||
|
||||
@@ -44,3 +44,18 @@ public final class DeprecatedPropertyKt {
|
||||
public deprecated final static method setTextExtVar(@org.jetbrains.annotations.NotNull p0: java.lang.Object, p1: int): void
|
||||
public deprecated final static method setTextGenExtVar(@org.jetbrains.annotations.NotNull p0: java.util.List, p1: int): void
|
||||
}
|
||||
|
||||
@kotlin.Metadata
|
||||
public final class I$DefaultImpls {
|
||||
// source: 'deprecatedProperty.kt'
|
||||
public synthetic deprecated static @kotlin.Deprecated method getId$annotations(p0: java.lang.Object): void
|
||||
public deprecated static method getId(@org.jetbrains.annotations.NotNull p0: I, p1: java.lang.Object): java.lang.Object
|
||||
public final inner class I$DefaultImpls
|
||||
}
|
||||
|
||||
@kotlin.Metadata
|
||||
public interface I {
|
||||
// source: 'deprecatedProperty.kt'
|
||||
public deprecated abstract method getId(p0: java.lang.Object): java.lang.Object
|
||||
public final inner class I$DefaultImpls
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user