From d4fc79da432cb6693cb012b98b28d754f422c132 Mon Sep 17 00:00:00 2001 From: Svyatoslav Scherbina Date: Thu, 9 Mar 2017 12:36:39 +0700 Subject: [PATCH] backend: fix type operator result type in autoboxing --- .../jetbrains/kotlin/backend/konan/lower/Autoboxing.kt | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/Autoboxing.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/Autoboxing.kt index 3ade142d048..cf1b1c5fe4b 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/Autoboxing.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/Autoboxing.kt @@ -17,6 +17,7 @@ import org.jetbrains.kotlin.ir.util.isNullConst import org.jetbrains.kotlin.ir.visitors.transformChildrenVoid import org.jetbrains.kotlin.types.KotlinType import org.jetbrains.kotlin.types.TypeUtils +import org.jetbrains.kotlin.types.typeUtil.makeNullable /** * Boxes and unboxes values of value types when necessary. @@ -75,8 +76,11 @@ private class AutoboxingTransformer(val context: Context) : AbstractValueUsageTr IrTypeOperator.CAST, IrTypeOperator.IMPLICIT_CAST, IrTypeOperator.IMPLICIT_NOTNULL, IrTypeOperator.SAFE_CAST -> { - // Codegen produces the object reference: - val newExpressionType = builtIns.nullableAnyType + val newExpressionType = if (expression.operator == IrTypeOperator.SAFE_CAST) { + newTypeOperand.makeNullable() + } else { + newTypeOperand + } IrTypeOperatorCallImpl(expression.startOffset, expression.endOffset, newExpressionType, expression.operator, newTypeOperand,