diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/descriptors/IrBasedDescriptors.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/descriptors/IrBasedDescriptors.kt index 34bf68e31d0..8d73ba75cb5 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/descriptors/IrBasedDescriptors.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/descriptors/IrBasedDescriptors.kt @@ -1132,8 +1132,13 @@ private fun getContainingDeclaration(declaration: IrDeclaration): DeclarationDes } fun IrType.toIrBasedKotlinType(): KotlinType = when (this) { - is IrSimpleType -> makeKotlinType(classifier, arguments, hasQuestionMark) - else -> TODO(toString()) + is IrSimpleType -> + makeKotlinType(classifier, arguments, hasQuestionMark) + is IrDefinitelyNotNullType -> + DefinitelyNotNullType.makeDefinitelyNotNull(this.original.toIrBasedKotlinType().unwrap()) + ?: throw AssertionError("Can't reconstruct a definitely not-null type: ${this.render()}") + else -> + TODO(toString()) } private fun makeKotlinType( diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/types/IrTypeSystemContext.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/types/IrTypeSystemContext.kt index 47f6bb7d0a0..64bd2fd47b5 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/types/IrTypeSystemContext.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/types/IrTypeSystemContext.kt @@ -84,6 +84,7 @@ interface IrTypeSystemContext : TypeSystemContext, TypeSystemCommonSuperTypesCon override fun SimpleTypeMarker.typeConstructor(): TypeConstructorMarker = when (this) { is IrCapturedType -> constructor is IrSimpleType -> classifier + is IrDefinitelyNotNullType -> original.typeConstructor() else -> error("Unknown type constructor") } @@ -549,7 +550,7 @@ interface IrTypeSystemContext : TypeSystemContext, TypeSystemCommonSuperTypesCon error("Captured type is unsupported in IR") override fun DefinitelyNotNullTypeMarker.original(): SimpleTypeMarker = - error("DefinitelyNotNull type is unsupported in IR") + (this as IrDefinitelyNotNullType).original as IrSimpleType override fun KotlinTypeMarker.makeDefinitelyNotNullOrNotNull(): KotlinTypeMarker { error("makeDefinitelyNotNullOrNotNull is not supported in IR") diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/types/impl/IrDefinitelyNotNullTypeImpl.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/types/impl/IrDefinitelyNotNullTypeImpl.kt new file mode 100644 index 00000000000..59522b04d36 --- /dev/null +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/types/impl/IrDefinitelyNotNullTypeImpl.kt @@ -0,0 +1,31 @@ +/* + * Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.ir.types.impl + +import org.jetbrains.kotlin.ir.expressions.IrConstructorCall +import org.jetbrains.kotlin.ir.types.IrDefinitelyNotNullType +import org.jetbrains.kotlin.ir.types.IrType +import org.jetbrains.kotlin.types.KotlinType +import org.jetbrains.kotlin.types.Variance + +class IrDefinitelyNotNullTypeImpl( + kotlinType: KotlinType?, + override val original: IrType, +) : IrTypeBase(kotlinType), IrDefinitelyNotNullType { + + override val annotations: List + get() = original.annotations + + override val variance: Variance + get() = Variance.INVARIANT + + override fun equals(other: Any?): Boolean = + other is IrDefinitelyNotNullType && + this.original == other.original + + override fun hashCode(): Int = + original.hashCode() +} \ No newline at end of file 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 9449183d533..888b2aac1c9 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 @@ -51,15 +51,6 @@ abstract class IrDelegatedSimpleType(kotlinType: KotlinType? = null) : IrAbstrac get() = delegate.annotations } -// TODO: This implementation is aligned with FE representation of DefinitelyNotNull (DNN) type but -// in fact DNN is special case of more general `IntersectionType` -// so someday it should be reconsidered -class IrDefinitelyNotNullTypeImpl(kotlinType: KotlinType?, original: IrType) : IrDelegatedSimpleType(kotlinType), IrDefinitelyNotNullType { - override val delegate: IrSimpleType = original as IrSimpleType - override val original: IrType - get() = delegate -} - class IrSimpleTypeImpl( kotlinType: KotlinType?, override val classifier: IrClassifierSymbol,