IR IrDefinitelyNotNullTypeImpl should not extend IrSimpleType

This commit is contained in:
Dmitry Petrov
2022-02-08 18:10:30 +03:00
committed by Space
parent d4d5c701fe
commit a565a17f3e
4 changed files with 40 additions and 12 deletions
@@ -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(
@@ -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")
@@ -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<IrConstructorCall>
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()
}
@@ -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,