From 662abba4a7567c023fde071880879f5c5ac51cdc Mon Sep 17 00:00:00 2001 From: Igor Chevdar Date: Wed, 29 Mar 2017 19:15:31 +0300 Subject: [PATCH] Changed type of exception from CastClassException to TypeCastException When converting from null to non-nullable type kotlin JVM throws TypeCastException --- .../kotlin/backend/konan/lower/TypeOperatorLowering.kt | 6 +++--- runtime/src/main/kotlin/konan/internal/RuntimeUtils.kt | 4 ++++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/TypeOperatorLowering.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/TypeOperatorLowering.kt index d8443899056..8cb8b9c67cf 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/TypeOperatorLowering.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/TypeOperatorLowering.kt @@ -52,8 +52,8 @@ private class TypeOperatorTransformer(val context: Context, val function: Functi private val builder = context.createIrBuilder(function) - val throwClassCastException by lazy { - context.builtIns.getKonanInternalFunctions("ThrowClassCastException").single() + val throwTypeCastException by lazy { + context.builtIns.getKonanInternalFunctions("ThrowTypeCastException").single() } override fun visitFunction(declaration: IrFunction): IrStatement { @@ -101,7 +101,7 @@ private class TypeOperatorTransformer(val context: Context, val function: Functi thenPart = if (typeOperand.isMarkedNullable) irNull() else - irCall(throwClassCastException), + irCall(throwTypeCastException), elsePart = irAs(irGet(argument), typeOperand.makeNotNullable()) ) diff --git a/runtime/src/main/kotlin/konan/internal/RuntimeUtils.kt b/runtime/src/main/kotlin/konan/internal/RuntimeUtils.kt index 3a7e5ec9c6b..af8ec91dd0f 100644 --- a/runtime/src/main/kotlin/konan/internal/RuntimeUtils.kt +++ b/runtime/src/main/kotlin/konan/internal/RuntimeUtils.kt @@ -31,6 +31,10 @@ fun ThrowClassCastException(): Nothing { throw ClassCastException() } +fun ThrowTypeCastException(): Nothing { + throw TypeCastException() +} + @ExportForCppRuntime internal fun ThrowArithmeticException() : Nothing { throw ArithmeticException()