IR IrDefinitelyNotNullTypeImpl should not extend IrSimpleType
This commit is contained in:
@@ -1132,8 +1132,13 @@ private fun getContainingDeclaration(declaration: IrDeclaration): DeclarationDes
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun IrType.toIrBasedKotlinType(): KotlinType = when (this) {
|
fun IrType.toIrBasedKotlinType(): KotlinType = when (this) {
|
||||||
is IrSimpleType -> makeKotlinType(classifier, arguments, hasQuestionMark)
|
is IrSimpleType ->
|
||||||
else -> TODO(toString())
|
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(
|
private fun makeKotlinType(
|
||||||
|
|||||||
@@ -84,6 +84,7 @@ interface IrTypeSystemContext : TypeSystemContext, TypeSystemCommonSuperTypesCon
|
|||||||
override fun SimpleTypeMarker.typeConstructor(): TypeConstructorMarker = when (this) {
|
override fun SimpleTypeMarker.typeConstructor(): TypeConstructorMarker = when (this) {
|
||||||
is IrCapturedType -> constructor
|
is IrCapturedType -> constructor
|
||||||
is IrSimpleType -> classifier
|
is IrSimpleType -> classifier
|
||||||
|
is IrDefinitelyNotNullType -> original.typeConstructor()
|
||||||
else -> error("Unknown type constructor")
|
else -> error("Unknown type constructor")
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -549,7 +550,7 @@ interface IrTypeSystemContext : TypeSystemContext, TypeSystemCommonSuperTypesCon
|
|||||||
error("Captured type is unsupported in IR")
|
error("Captured type is unsupported in IR")
|
||||||
|
|
||||||
override fun DefinitelyNotNullTypeMarker.original(): SimpleTypeMarker =
|
override fun DefinitelyNotNullTypeMarker.original(): SimpleTypeMarker =
|
||||||
error("DefinitelyNotNull type is unsupported in IR")
|
(this as IrDefinitelyNotNullType).original as IrSimpleType
|
||||||
|
|
||||||
override fun KotlinTypeMarker.makeDefinitelyNotNullOrNotNull(): KotlinTypeMarker {
|
override fun KotlinTypeMarker.makeDefinitelyNotNullOrNotNull(): KotlinTypeMarker {
|
||||||
error("makeDefinitelyNotNullOrNotNull is not supported in IR")
|
error("makeDefinitelyNotNullOrNotNull is not supported in IR")
|
||||||
|
|||||||
+31
@@ -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
|
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(
|
class IrSimpleTypeImpl(
|
||||||
kotlinType: KotlinType?,
|
kotlinType: KotlinType?,
|
||||||
override val classifier: IrClassifierSymbol,
|
override val classifier: IrClassifierSymbol,
|
||||||
|
|||||||
Reference in New Issue
Block a user