From 9bdbbb44cf84f92146637c4868076a0b0cc1bb8c Mon Sep 17 00:00:00 2001 From: Ilmir Usmanov Date: Thu, 30 Dec 2021 18:14:26 +0100 Subject: [PATCH] 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 --- .../kotlin/backend/jvm/codegen/ExpressionCodegen.kt | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/compiler/ir/backend.jvm/codegen/src/org/jetbrains/kotlin/backend/jvm/codegen/ExpressionCodegen.kt b/compiler/ir/backend.jvm/codegen/src/org/jetbrains/kotlin/backend/jvm/codegen/ExpressionCodegen.kt index 7a7853f2103..0a766f0c379 100644 --- a/compiler/ir/backend.jvm/codegen/src/org/jetbrains/kotlin/backend/jvm/codegen/ExpressionCodegen.kt +++ b/compiler/ir/backend.jvm/codegen/src/org/jetbrains/kotlin/backend/jvm/codegen/ExpressionCodegen.kt @@ -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"