JVM_IR. Generate proper suffix for companion backing field accessor and parameter name
This commit is contained in:
@@ -45,4 +45,5 @@ interface JvmLoweredDeclarationOrigin : IrDeclarationOrigin {
|
||||
object FOR_INLINE_STATE_MACHINE_TEMPLATE : IrDeclarationOriginImpl("FOR_INLINE_TEMPLATE")
|
||||
object FOR_INLINE_STATE_MACHINE_TEMPLATE_CAPTURES_CROSSINLINE : IrDeclarationOriginImpl("FOR_INLINE_TEMPLATE_CROSSINLINE")
|
||||
object FOR_INLINE_STATE_MACHINE_TEMPLATE_CAPTURES_CROSSINLINE_VIEW : IrDeclarationOriginImpl("FOR_INLINE_TEMPLATE_CROSSINLINE_VIEW")
|
||||
object COMPANION_PROPERTY_BACKING_FIELD : IrDeclarationOriginImpl("COMPANION_MOVED_PROPERTY_BACKING_FIELD")
|
||||
}
|
||||
|
||||
+1
-1
@@ -26,7 +26,6 @@ import org.jetbrains.kotlin.ir.descriptors.WrappedClassDescriptor
|
||||
import org.jetbrains.kotlin.ir.descriptors.WrappedValueParameterDescriptor
|
||||
import org.jetbrains.kotlin.ir.expressions.IrExpressionBody
|
||||
import org.jetbrains.kotlin.ir.symbols.impl.*
|
||||
import org.jetbrains.kotlin.ir.types.IrType
|
||||
import org.jetbrains.kotlin.ir.util.*
|
||||
import org.jetbrains.kotlin.load.java.JavaVisibilities
|
||||
import org.jetbrains.kotlin.load.java.JvmAbi
|
||||
@@ -181,6 +180,7 @@ class JvmDeclarationFactory(
|
||||
initializer = oldField.initializer
|
||||
?.replaceThisByStaticReference(this@JvmDeclarationFactory, oldParent, oldParent.thisReceiver!!)
|
||||
?.patchDeclarationParents(this) as IrExpressionBody?
|
||||
origin = if (irProperty.parentAsClass.isCompanion) JvmLoweredDeclarationOrigin.COMPANION_PROPERTY_BACKING_FIELD else origin
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+6
-8
@@ -7,7 +7,6 @@ package org.jetbrains.kotlin.backend.jvm.lower
|
||||
|
||||
import org.jetbrains.kotlin.backend.common.FileLoweringPass
|
||||
import org.jetbrains.kotlin.backend.common.IrElementTransformerVoidWithContext
|
||||
import org.jetbrains.kotlin.backend.common.descriptors.synthesizedName
|
||||
import org.jetbrains.kotlin.backend.common.descriptors.synthesizedString
|
||||
import org.jetbrains.kotlin.backend.common.ir.*
|
||||
import org.jetbrains.kotlin.backend.jvm.JvmBackendContext
|
||||
@@ -322,7 +321,7 @@ internal class SyntheticAccessorLowering(val context: JvmBackendContext) : IrEle
|
||||
)
|
||||
}
|
||||
|
||||
accessor.addValueParameter("value", fieldSymbol.owner.type, JvmLoweredDeclarationOrigin.SYNTHETIC_ACCESSOR)
|
||||
accessor.addValueParameter("<set-?>", fieldSymbol.owner.type, JvmLoweredDeclarationOrigin.SYNTHETIC_ACCESSOR)
|
||||
|
||||
accessor.body = createAccessorBodyForSetter(fieldSymbol.owner, accessor)
|
||||
}.symbol
|
||||
@@ -492,15 +491,14 @@ internal class SyntheticAccessorLowering(val context: JvmBackendContext) : IrEle
|
||||
}
|
||||
|
||||
private fun IrField.fieldAccessorSuffix(): String {
|
||||
// The only static field accessors are those for fields moved from companion objects, hence a
|
||||
// _c_ompanion _p_roperty suffix. However, companion objects for interfaces keep their fields
|
||||
// (as interfaces cannot own fields), hence are simple _p_roperty accessors, like everything else.
|
||||
val companionSuffix = if (isStatic && !parentAsClass.isCompanion) "cp" else "p"
|
||||
// Special _c_ompanion _p_roperty suffix for accessing companion backing field moved to outer
|
||||
if (origin == JvmLoweredDeclarationOrigin.COMPANION_PROPERTY_BACKING_FIELD && !parentAsClass.isCompanion) {
|
||||
return "cp"
|
||||
}
|
||||
|
||||
// Static accesses that need an accessor must be due to being inherited, hence accessed on a
|
||||
// _s_upertype
|
||||
val staticSuffix = if (isStatic) "\$s" + parentAsClass.descriptor.syntheticAccessorToSuperSuffix() else ""
|
||||
return companionSuffix + staticSuffix
|
||||
return "p" + if (isStatic) "\$s" + parentAsClass.descriptor.syntheticAccessorToSuperSuffix() else ""
|
||||
}
|
||||
|
||||
private val Visibility.isPrivate
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// IGNORE_BACKEND: JVM_IR
|
||||
// KOTLIN_CONFIGURATION_FLAGS: +JVM.EMIT_JVM_TYPE_ANNOTATIONS
|
||||
// TYPE_ANNOTATIONS
|
||||
// IGNORE_BACKEND_FIR: JVM_IR
|
||||
|
||||
Reference in New Issue
Block a user