Do not generate not-null assertions if underlying type is nullable

in case of deep upper bound hierarchy of generic underlying value,
especially when upper bound is another inline class with generic
underlying value.
 #KT-32162
This commit is contained in:
Ilmir Usmanov
2021-12-30 18:14:26 +01:00
parent a7e2f7a6b6
commit 9bdbbb44cf
@@ -50,6 +50,7 @@ import org.jetbrains.kotlin.resolve.jvm.AsmTypes.OBJECT_TYPE
import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodParameterKind
import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodSignature
import org.jetbrains.kotlin.types.TypeSystemCommonBackendContext
import org.jetbrains.kotlin.types.computeExpandedTypeForInlineClass
import org.jetbrains.kotlin.types.model.TypeParameterMarker
import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstanceOrNull
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
@@ -330,7 +331,11 @@ class ExpressionCodegen(
)
return
val asmType = param.type.asmType
if (!param.type.unboxInlineClass().isNullable() && !isPrimitive(asmType)) {
val expandedType =
if (param.type.isInlineClassType())
context.typeSystem.computeExpandedTypeForInlineClass(param.type) as? IrType ?: param.type
else param.type
if (!expandedType.isNullable() && !isPrimitive(asmType)) {
mv.load(findLocalIndex(param.symbol), asmType)
mv.aconst(param.name.asString())
val methodName = if (state.unifiedNullChecks) "checkNotNullParameter" else "checkParameterIsNotNull"