From 4326e26907c4ba1e69cf70905aac77baf18d1613 Mon Sep 17 00:00:00 2001 From: Dmitry Petrov Date: Tue, 8 Feb 2022 18:10:48 +0300 Subject: [PATCH] JVM_IR Support IrDefinitelyNotNullType --- .../kotlin/types/AbstractTypeMapper.kt | 4 ++++ .../kotlin/backend/jvm/ir/JvmIrTypeUtils.kt | 21 ++++++++++++------- .../backend/jvm/mapping/IrTypeMapper.kt | 2 +- 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/compiler/backend.common.jvm/src/org/jetbrains/kotlin/types/AbstractTypeMapper.kt b/compiler/backend.common.jvm/src/org/jetbrains/kotlin/types/AbstractTypeMapper.kt index 61373fe461e..1df02a3da17 100644 --- a/compiler/backend.common.jvm/src/org/jetbrains/kotlin/types/AbstractTypeMapper.kt +++ b/compiler/backend.common.jvm/src/org/jetbrains/kotlin/types/AbstractTypeMapper.kt @@ -54,6 +54,10 @@ object AbstractTypeMapper { mode: TypeMappingMode = TypeMappingMode.DEFAULT, sw: Writer? = null ): Type { + if (type is DefinitelyNotNullTypeMarker) { + return mapType(context, type.original(), mode, sw) + } + if (type is SimpleTypeMarker && type.isSuspendFunction()) { val argumentsCount = type.argumentsCount() val argumentsList = type.asArgumentList() diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/ir/JvmIrTypeUtils.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/ir/JvmIrTypeUtils.kt index eaf7d82d56c..d54e1484a72 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/ir/JvmIrTypeUtils.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/ir/JvmIrTypeUtils.kt @@ -36,7 +36,6 @@ import org.jetbrains.kotlin.utils.addToStdlib.safeAs * `T : Comparable` is replaced by `Comparable<*>`. */ fun IrType.eraseTypeParameters(): IrType = when (this) { - is IrErrorType -> this is IrSimpleType -> when (val owner = classifier.owner) { is IrScript -> { @@ -56,6 +55,10 @@ fun IrType.eraseTypeParameters(): IrType = when (this) { } else -> error("Unknown IrSimpleType classifier kind: $owner") } + is IrDefinitelyNotNullType -> + this.original.eraseTypeParameters() + is IrErrorType -> + this else -> error("Unknown IrType kind: $this") } @@ -83,12 +86,16 @@ val IrTypeParameter.erasedUpperBound: IrClass } val IrType.erasedUpperBound: IrClass - get() = when (val classifier = classifierOrNull) { - is IrClassSymbol -> classifier.owner - is IrTypeParameterSymbol -> classifier.owner.erasedUpperBound - is IrScriptSymbol -> classifier.owner.targetClass!!.owner - else -> error(render()) - } + get() = + if (this is IrDefinitelyNotNullType) + this.original.erasedUpperBound + else + when (val classifier = classifierOrNull) { + is IrClassSymbol -> classifier.owner + is IrTypeParameterSymbol -> classifier.owner.erasedUpperBound + is IrScriptSymbol -> classifier.owner.targetClass!!.owner + else -> error(render()) + } /** * Get the default null/0 value for the type. diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/mapping/IrTypeMapper.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/mapping/IrTypeMapper.kt index 8d08acb7ae1..3eed8c597b7 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/mapping/IrTypeMapper.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/mapping/IrTypeMapper.kt @@ -239,7 +239,7 @@ private class IrTypeCheckerContextForTypeMapping( } override fun SimpleTypeMarker.isSuspendFunction(): Boolean { - require(this is IrSimpleType) + if (this !is IrSimpleType) return false return isSuspendFunctionImpl() }