From 29728efbf70410bc36281d78af49f85f8dbc82d6 Mon Sep 17 00:00:00 2001 From: Roman Artemev Date: Mon, 25 Oct 2021 21:16:59 +0300 Subject: [PATCH] [PSI2IR] Support `DefinitelyNotNull` type translation in Psi2Ir --- .../org/jetbrains/kotlin/ir/util/TypeTranslator.kt | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) 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 cda36468352..bd2c7798dea 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 @@ -20,7 +20,6 @@ import org.jetbrains.kotlin.ir.types.IrType import org.jetbrains.kotlin.ir.types.IrTypeAbbreviation import org.jetbrains.kotlin.ir.types.IrTypeProjection import org.jetbrains.kotlin.ir.types.impl.* -import org.jetbrains.kotlin.resolve.descriptorUtil.module import org.jetbrains.kotlin.types.* import org.jetbrains.kotlin.types.typeUtil.replaceArgumentsWithStarProjections import org.jetbrains.kotlin.types.typesApproximation.approximateCapturedTypes @@ -45,6 +44,8 @@ abstract class TypeTranslator( private val erasureStack = Stack() + private val supportDefinitelyNotNullTypes: Boolean = languageVersionSettings.supportsFeature(LanguageFeature.DefinitelyNonNullableTypes) + protected abstract fun isTypeAliasAccessibleHere(typeAliasDescriptor: TypeAliasDescriptor): Boolean fun enterScope(irElement: IrTypeParametersContainer) { @@ -86,17 +87,20 @@ abstract class TypeTranslator( ?: symbolTable.referenceTypeParameter(originalTypeParameter) } - fun translateType(kotlinType: KotlinType): IrType = - translateType(kotlinType, Variance.INVARIANT).type + fun translateType(kotlinType: KotlinType): IrType { + return translateType(kotlinType, Variance.INVARIANT).type + } private fun translateType(kotlinType: KotlinType, variance: Variance): IrTypeProjection { - val approximatedType = approximate(kotlinType) + val approximatedType = approximate(kotlinType.unwrap()) when { approximatedType.isError -> return IrErrorTypeImpl(approximatedType, translateTypeAnnotations(approximatedType), variance) approximatedType.isDynamic() -> return IrDynamicTypeImpl(approximatedType, translateTypeAnnotations(approximatedType), variance) + supportDefinitelyNotNullTypes && approximatedType is DefinitelyNotNullType -> + return makeTypeProjection(IrDefinitelyNotNullTypeImpl(approximatedType, translateType(approximatedType.original)), variance) } val upperType = approximatedType.upperIfFlexible()