Rework nullability in IR

This commit is contained in:
Pavel Kunyavskiy
2022-03-18 13:40:20 +03:00
committed by Space
parent 000165b12b
commit 7ba4d9e1f0
108 changed files with 1679 additions and 469 deletions
@@ -469,7 +469,7 @@ class ExportModelGenerator(
return ExportedType.ErrorType("NonSimpleType ${type.render()}")
val classifier = type.classifier
val isNullable = type.hasQuestionMark
val isMarkedNullable = type.isMarkedNullable()
val nonNullType = type.makeNotNull() as IrSimpleType
val exportedType = when {
@@ -528,7 +528,7 @@ class ExportModelGenerator(
else -> error("Unexpected classifier $classifier")
}
return exportedType.withNullability(isNullable)
return exportedType.withNullability(isMarkedNullable)
}
private fun IrClass.getExportableName(): String {
@@ -74,7 +74,7 @@ class ScriptRemoveReceiverLowering(val context: CommonBackendContext) : FileLowe
endOffset,
IrSimpleTypeImpl(
context.ir.symbols.functionN(newN),
(type as IrSimpleType).hasQuestionMark,
(type as IrSimpleType).nullability,
arguments,
type.annotations
),
@@ -111,7 +111,7 @@ class ScriptRemoveReceiverLowering(val context: CommonBackendContext) : FileLowe
endOffset,
IrSimpleTypeImpl(
(if (setter == null) getPropertyN(newN) else getMutablePropertyN(newN)),
(type as IrSimpleType).hasQuestionMark,
(type as IrSimpleType).nullability,
arguments,
type.annotations
),
@@ -13,7 +13,6 @@ import org.jetbrains.kotlin.ir.symbols.IrScriptSymbol
import org.jetbrains.kotlin.ir.symbols.IrTypeParameterSymbol
import org.jetbrains.kotlin.ir.types.*
import org.jetbrains.kotlin.ir.util.fqNameWhenAvailable
import org.jetbrains.kotlin.ir.util.getInlineClassUnderlyingType
import org.jetbrains.kotlin.ir.util.isEffectivelyExternal
import org.jetbrains.kotlin.js.backend.ast.JsNameRef
import org.jetbrains.kotlin.types.Variance
@@ -26,7 +25,11 @@ fun IrType.asString(): String = when (this) {
is IrDynamicType -> "dynamic"
is IrSimpleType ->
classifier.asString() +
(if (hasQuestionMark) "?" else "") +
when (nullability) {
SimpleTypeNullability.MARKED_NULLABLE -> "?"
SimpleTypeNullability.NOT_SPECIFIED -> ""
SimpleTypeNullability.DEFINITELY_NOT_NULL -> if (classifier is IrTypeParameterSymbol) " & Any" else ""
} +
(arguments.ifNotEmpty {
joinToString(separator = ",", prefix = "<", postfix = ">") { it.asString() }
} ?: "")
@@ -34,11 +34,8 @@ private val IrTypeParameter.erasedUpperBound: IrClass?
val IrType.erasedUpperBound: IrClass?
get() =
if (this is IrDefinitelyNotNullType)
this.original.erasedUpperBound
else
when (val classifier = classifierOrNull) {
is IrClassSymbol -> classifier.owner
is IrTypeParameterSymbol -> classifier.owner.erasedUpperBound
else -> throw IllegalStateException()
}
when (val classifier = classifierOrNull) {
is IrClassSymbol -> classifier.owner
is IrTypeParameterSymbol -> classifier.owner.erasedUpperBound
else -> throw IllegalStateException()
}