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
@@ -194,7 +194,11 @@ internal fun IrFunction.getArgsForMethodInvocation(
internal fun IrType.getOnlyName(): String {
if (this !is IrSimpleType) return this.render()
return (this.classifierOrFail.owner as IrDeclarationWithName).name.asString() + (if (this.hasQuestionMark) "?" else "")
return (this.classifierOrFail.owner as IrDeclarationWithName).name.asString() + when (nullability) {
SimpleTypeNullability.MARKED_NULLABLE -> "?"
SimpleTypeNullability.NOT_SPECIFIED -> ""
SimpleTypeNullability.DEFINITELY_NOT_NULL -> if (this.classifierOrNull is IrTypeParameterSymbol) " & Any" else ""
}
}
internal fun IrFieldAccessExpression.accessesTopLevelOrObjectField(): Boolean {
@@ -251,7 +255,7 @@ internal fun IrType.getTypeIfReified(getType: (IrClassifierSymbol) -> IrType): I
val owner = this.classifierOrNull?.owner
if (owner is IrTypeParameter && owner.isReified) {
return (getType(owner.symbol) as IrSimpleType)
.buildSimpleType { hasQuestionMark = this.hasQuestionMark || this@getTypeIfReified.hasQuestionMark }
.mergeNullability(this)
}
val newArguments = this.arguments.map {
@@ -261,7 +265,6 @@ internal fun IrType.getTypeIfReified(getType: (IrClassifierSymbol) -> IrType): I
type.getTypeIfReified(getType) as IrTypeArgument
}
return this.buildSimpleType {
hasQuestionMark = this.hasQuestionMark || this@getTypeIfReified.hasQuestionMark
arguments = newArguments
}
}
@@ -172,7 +172,7 @@ internal class Wrapper(val value: Any, override val irClass: IrClass, environmen
fun getStaticGetter(field: IrField): MethodHandle {
val jvmClass = field.parentAsClass.defaultType.getClass(true)
val returnType = field.type.let { it.getClass((it as IrSimpleType).hasQuestionMark) }
val returnType = field.type.let { it.getClass(it.isNullable()) }
return MethodHandles.lookup().findStaticGetter(jvmClass, field.name.asString(), returnType)
}