From 12235faa3906617ea4d371fd56dfcfd2ac713a62 Mon Sep 17 00:00:00 2001 From: Michael Bogdanov Date: Wed, 5 Oct 2016 14:23:07 +0300 Subject: [PATCH] Return proper type after cast --- .../kotlin/backend/jvm/codegen/ExpressionCodegen.kt | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/ExpressionCodegen.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/ExpressionCodegen.kt index 0a17dff95b0..fabe9297d2c 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/ExpressionCodegen.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/ExpressionCodegen.kt @@ -506,6 +506,7 @@ class ExpressionCodegen( override fun visitTypeOperator(expression: IrTypeOperatorCall, data: BlockInfo): StackValue { + val asmType = expression.typeOperand.asmType when (expression.operator) { IrTypeOperator.IMPLICIT_COERCION_TO_UNIT -> { expression.argument.accept(this, data) @@ -513,7 +514,7 @@ class ExpressionCodegen( return none() } IrTypeOperator.IMPLICIT_CAST -> { - gen(expression.argument, expression.typeOperand.asmType, data) + gen(expression.argument, asmType, data) } IrTypeOperator.CAST, IrTypeOperator.SAFE_CAST -> { @@ -522,12 +523,14 @@ class ExpressionCodegen( if (value.type === Type.VOID_TYPE) { StackValue.putUnitInstance(mv) } - generateAsCast(mv, expression.typeOperand, boxType(expression.typeOperand.asmType), expression.operator == IrTypeOperator.SAFE_CAST) + val boxedType = boxType(asmType) + generateAsCast(mv, expression.typeOperand, boxedType, expression.operator == IrTypeOperator.SAFE_CAST) + return onStack(boxedType) } IrTypeOperator.INSTANCEOF -> { gen(expression.argument, OBJECT_TYPE, data) - val type = boxType(expression.typeOperand.asmType) + val type = boxType(asmType) generateIsCheck(mv, expression.typeOperand, type) }