From 6bd4d72b813851743908714ecfbbfd1eb00febca Mon Sep 17 00:00:00 2001 From: Alexander Udalov Date: Tue, 26 Mar 2019 17:03:44 +0100 Subject: [PATCH] Use more correct KProperty type in PropertyReferenceLowering Default type is `KProperty` where R is KProperty's type parameter. This type doesn't make much sense outside the KProperty's own class declaration. A more correct type here is `KProperty<*>`, which is the type used in property delegates in Kotlin --- .../backend/jvm/lower/PropertyReferenceLowering.kt | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/PropertyReferenceLowering.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/PropertyReferenceLowering.kt index 93409267c84..2ed96d1d5c0 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/PropertyReferenceLowering.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/PropertyReferenceLowering.kt @@ -75,11 +75,15 @@ internal class PropertyReferenceLowering(val context: JvmBackendContext) : Class private val arrayItemGetter = context.ir.symbols.array.owner.functions.single { it.name.asString() == "get" } - private val kPropertyType = - context.getIrClass(FqName("kotlin.reflect.KProperty")).owner.defaultType + private val kPropertyStarType = IrSimpleTypeImpl( + context.irBuiltIns.kPropertyClass, + false, + listOf(makeTypeProjection(context.irBuiltIns.anyNType, Variance.OUT_VARIANCE)), + emptyList() + ) private val kPropertiesFieldType = - context.ir.symbols.array.createType(false, listOf(makeTypeProjection(kPropertyType, Variance.OUT_VARIANCE))) + context.ir.symbols.array.createType(false, listOf(makeTypeProjection(kPropertyStarType, Variance.OUT_VARIANCE))) // Return some declaration the parent of which is the containing class/package for the referenced property. This is // a bit of a hack, as the reason for not returning the container itself is the `mapImplementationOwner` call below. @@ -365,7 +369,7 @@ internal class PropertyReferenceLowering(val context: JvmBackendContext) : Class initializer = context.createIrBuilder(irClass.symbol).run { val initializers = kProperties.values.sortedBy { it.index }.map { it.initializer } irExprBody(irCall(this@PropertyReferenceLowering.context.ir.symbols.arrayOf).apply { - putValueArgument(0, IrVarargImpl(startOffset, endOffset, kPropertiesFieldType, kPropertyType, initializers)) + putValueArgument(0, IrVarargImpl(startOffset, endOffset, kPropertiesFieldType, kPropertyStarType, initializers)) }) } })