JVM_IR Support IrDefinitelyNotNullType

This commit is contained in:
Dmitry Petrov
2022-02-08 18:10:48 +03:00
committed by Space
parent a565a17f3e
commit 4326e26907
3 changed files with 19 additions and 8 deletions
@@ -54,6 +54,10 @@ object AbstractTypeMapper {
mode: TypeMappingMode = TypeMappingMode.DEFAULT, mode: TypeMappingMode = TypeMappingMode.DEFAULT,
sw: Writer? = null sw: Writer? = null
): Type { ): Type {
if (type is DefinitelyNotNullTypeMarker) {
return mapType(context, type.original(), mode, sw)
}
if (type is SimpleTypeMarker && type.isSuspendFunction()) { if (type is SimpleTypeMarker && type.isSuspendFunction()) {
val argumentsCount = type.argumentsCount() val argumentsCount = type.argumentsCount()
val argumentsList = type.asArgumentList() val argumentsList = type.asArgumentList()
@@ -36,7 +36,6 @@ import org.jetbrains.kotlin.utils.addToStdlib.safeAs
* `T : Comparable<T>` is replaced by `Comparable<*>`. * `T : Comparable<T>` is replaced by `Comparable<*>`.
*/ */
fun IrType.eraseTypeParameters(): IrType = when (this) { fun IrType.eraseTypeParameters(): IrType = when (this) {
is IrErrorType -> this
is IrSimpleType -> is IrSimpleType ->
when (val owner = classifier.owner) { when (val owner = classifier.owner) {
is IrScript -> { is IrScript -> {
@@ -56,6 +55,10 @@ fun IrType.eraseTypeParameters(): IrType = when (this) {
} }
else -> error("Unknown IrSimpleType classifier kind: $owner") else -> error("Unknown IrSimpleType classifier kind: $owner")
} }
is IrDefinitelyNotNullType ->
this.original.eraseTypeParameters()
is IrErrorType ->
this
else -> error("Unknown IrType kind: $this") else -> error("Unknown IrType kind: $this")
} }
@@ -83,12 +86,16 @@ val IrTypeParameter.erasedUpperBound: IrClass
} }
val IrType.erasedUpperBound: IrClass val IrType.erasedUpperBound: IrClass
get() = when (val classifier = classifierOrNull) { get() =
is IrClassSymbol -> classifier.owner if (this is IrDefinitelyNotNullType)
is IrTypeParameterSymbol -> classifier.owner.erasedUpperBound this.original.erasedUpperBound
is IrScriptSymbol -> classifier.owner.targetClass!!.owner else
else -> error(render()) 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. * Get the default null/0 value for the type.
@@ -239,7 +239,7 @@ private class IrTypeCheckerContextForTypeMapping(
} }
override fun SimpleTypeMarker.isSuspendFunction(): Boolean { override fun SimpleTypeMarker.isSuspendFunction(): Boolean {
require(this is IrSimpleType) if (this !is IrSimpleType) return false
return isSuspendFunctionImpl() return isSuspendFunctionImpl()
} }