diff --git a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/descriptors/IrDescriptorBasedFunctionFactory.kt b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/descriptors/IrDescriptorBasedFunctionFactory.kt index 655c70cc97c..7fe2640f732 100644 --- a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/descriptors/IrDescriptorBasedFunctionFactory.kt +++ b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/descriptors/IrDescriptorBasedFunctionFactory.kt @@ -20,7 +20,10 @@ import org.jetbrains.kotlin.ir.symbols.IrTypeParameterSymbol import org.jetbrains.kotlin.ir.symbols.impl.IrValueParameterSymbolImpl import org.jetbrains.kotlin.ir.types.IrType import org.jetbrains.kotlin.ir.types.SimpleTypeNullability -import org.jetbrains.kotlin.ir.types.impl.* +import org.jetbrains.kotlin.ir.types.impl.IrSimpleTypeBuilder +import org.jetbrains.kotlin.ir.types.impl.IrStarProjectionImpl +import org.jetbrains.kotlin.ir.types.impl.buildSimpleType +import org.jetbrains.kotlin.ir.types.impl.makeTypeProjection import org.jetbrains.kotlin.ir.util.* import org.jetbrains.kotlin.name.FqName import org.jetbrains.kotlin.name.Name @@ -516,7 +519,7 @@ class IrDescriptorBasedFunctionFactory( arguments = listOf( with(IrSimpleTypeBuilder()) { classifier = r.symbol - buildTypeProjection() + buildSimpleType() }, ) buildSimpleType() diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/types/impl/IrSimpleTypeImpl.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/types/impl/IrSimpleTypeImpl.kt index af6a68663ee..954fe5b5683 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/types/impl/IrSimpleTypeImpl.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/types/impl/IrSimpleTypeImpl.kt @@ -89,7 +89,6 @@ class IrSimpleTypeBuilder { var arguments: List = emptyList() var annotations: List = emptyList() var abbreviation: IrTypeAbbreviation? = null - var variance = Variance.INVARIANT } fun IrSimpleType.toBuilder() = @@ -112,7 +111,7 @@ fun IrSimpleTypeBuilder.buildSimpleType() = abbreviation ) -fun IrSimpleTypeBuilder.buildTypeProjection() = +fun IrSimpleTypeBuilder.buildTypeProjection(variance: Variance): IrTypeProjection = if (variance == Variance.INVARIANT) buildSimpleType() else @@ -136,13 +135,12 @@ fun makeTypeProjection(type: IrType, variance: Variance): IrTypeProjection = when { type is IrCapturedType -> IrTypeProjectionImpl(type, variance) type is IrTypeProjection && type.variance == variance -> type - type is IrSimpleType -> type.toBuilder().apply { this.variance = variance }.buildTypeProjection() + type is IrSimpleType -> type.toBuilder().buildTypeProjection(variance) type is IrDynamicType -> IrDynamicTypeImpl(null, type.annotations, variance) type is IrErrorType -> IrErrorTypeImpl(null, type.annotations, variance) else -> IrTypeProjectionImpl(type, variance) } - fun makeTypeIntersection(types: List): IrType = with(types.map { makeTypeProjection(it, Variance.INVARIANT).type }.distinct()) { if (size == 1) return single() diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/TypeTranslator.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/TypeTranslator.kt index 487402fce85..3a4c41784ad 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/TypeTranslator.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/TypeTranslator.kt @@ -126,7 +126,6 @@ abstract class TypeTranslator( return IrSimpleTypeBuilder().apply { this.kotlinType = approximatedType this.nullability = SimpleTypeNullability.fromHasQuestionMark(upperType.isMarkedNullable) - this.variance = variance this.abbreviation = upperType.getAbbreviation()?.toIrTypeAbbreviation() when (upperTypeDescriptor) { @@ -169,7 +168,7 @@ abstract class TypeTranslator( else -> throw AssertionError("Unexpected type descriptor $upperTypeDescriptor :: ${upperTypeDescriptor::class}") } - }.buildTypeProjection() + }.buildTypeProjection(variance) } private fun approximateUpperBounds(upperBounds: Collection, variance: Variance): IrTypeProjection { diff --git a/compiler/ir/serialization.common/src/org/jetbrains/kotlin/backend/common/serialization/IrBodyDeserializer.kt b/compiler/ir/serialization.common/src/org/jetbrains/kotlin/backend/common/serialization/IrBodyDeserializer.kt index 23bc655b59c..e72283599ed 100644 --- a/compiler/ir/serialization.common/src/org/jetbrains/kotlin/backend/common/serialization/IrBodyDeserializer.kt +++ b/compiler/ir/serialization.common/src/org/jetbrains/kotlin/backend/common/serialization/IrBodyDeserializer.kt @@ -212,7 +212,7 @@ class IrBodyDeserializer( val rawType = with(IrSimpleTypeBuilder()) { arguments = typeParameters.memoryOptimizedMap { classifier = it.symbol - buildTypeProjection() + buildSimpleType() } classifier = klass.symbol buildSimpleType()