From e640f01b4e630ba98b9d912c44e391fa9260233c Mon Sep 17 00:00:00 2001 From: Igor Chevdar Date: Sun, 23 Dec 2018 22:10:50 +0300 Subject: [PATCH] Fixed bug with IR parameter copying. Constructors don't have their own type parameters but rather inherit them from the parent. --- .../src/org/jetbrains/kotlin/backend/common/ir/IrUtils.kt | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/ir/IrUtils.kt b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/ir/IrUtils.kt index 04f4a7d8f0e..fc5c943f67e 100644 --- a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/ir/IrUtils.kt +++ b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/ir/IrUtils.kt @@ -45,6 +45,7 @@ import org.jetbrains.kotlin.ir.types.impl.IrSimpleTypeImpl import org.jetbrains.kotlin.ir.types.impl.makeTypeProjection import org.jetbrains.kotlin.ir.util.DumpIrTreeVisitor import org.jetbrains.kotlin.ir.util.defaultType +import org.jetbrains.kotlin.ir.util.parentAsClass import org.jetbrains.kotlin.ir.util.patchDeclarationParents import org.jetbrains.kotlin.ir.visitors.IrElementVisitor import org.jetbrains.kotlin.name.Name @@ -145,6 +146,8 @@ val IrSimpleFunction.isOverridableOrOverrides: Boolean get() = isOverridable || val IrClass.isFinalClass: Boolean get() = modality == Modality.FINAL && kind != ClassKind.ENUM_CLASS +val IrTypeParametersContainer.classIfConstructor get() = if (this is IrConstructor) parentAsClass else this + fun IrValueParameter.copyTo( irFunction: IrFunction, origin: IrDeclarationOrigin = this.origin, @@ -152,7 +155,10 @@ fun IrValueParameter.copyTo( startOffset: Int = this.startOffset, endOffset: Int = this.endOffset, name: Name = this.name, - type: IrType = this.type.remapTypeParameters(this.parent as IrTypeParametersContainer, irFunction), + type: IrType = this.type.remapTypeParameters( + (parent as IrTypeParametersContainer).classIfConstructor, + irFunction.classIfConstructor + ), varargElementType: IrType? = this.varargElementType ): IrValueParameter { val descriptor = WrappedValueParameterDescriptor(symbol.descriptor.annotations, symbol.descriptor.source)