diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/KonanLoweringPhases.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/KonanLoweringPhases.kt index bcbcea262ac..3c386215bca 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/KonanLoweringPhases.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/KonanLoweringPhases.kt @@ -171,6 +171,12 @@ internal val stringConcatenationPhase = makeKonanFileLoweringPhase( description = "String concatenation lowering" ) +internal val kotlinNothingValueExceptionPhase = makeKonanFileLoweringPhase( + ::KotlinNothingValueExceptionLowering, + name = "KotlinNothingValueException", + description = "Throw proper exception for calls returning value of type 'kotlin.Nothing'" +) + internal val enumConstructorsPhase = makeKonanFileLoweringPhase( ::EnumConstructorsLowering, name = "EnumConstructors", diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/ToplevelPhases.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/ToplevelPhases.kt index c0f17131b98..132ffda2508 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/ToplevelPhases.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/ToplevelPhases.kt @@ -355,6 +355,7 @@ internal val allLoweringsPhase = namedIrModulePhase( typeOperatorPhase then bridgesPhase then autoboxPhase then + kotlinNothingValueExceptionPhase then returnsInsertionPhase ), actions = setOf(defaultDumper, ::moduleValidationCallback) diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/ir/Ir.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/ir/Ir.kt index e1a39ed5d38..ec5c3b61500 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/ir/Ir.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/ir/Ir.kt @@ -260,6 +260,8 @@ internal class KonanSymbols( override val ThrowTypeCastException = internalFunction("ThrowTypeCastException") + override val ThrowKotlinNothingValueException = internalFunction("ThrowKotlinNothingValueException") + val throwClassCastException = internalFunction("ThrowClassCastException") val throwInvalidReceiverTypeException = internalFunction("ThrowInvalidReceiverTypeException") diff --git a/runtime/src/main/kotlin/kotlin/native/internal/RuntimeUtils.kt b/runtime/src/main/kotlin/kotlin/native/internal/RuntimeUtils.kt index 2790ff08e76..f4cdde2d06d 100644 --- a/runtime/src/main/kotlin/kotlin/native/internal/RuntimeUtils.kt +++ b/runtime/src/main/kotlin/kotlin/native/internal/RuntimeUtils.kt @@ -34,6 +34,11 @@ fun ThrowTypeCastException(): Nothing { throw TypeCastException() } +@ExportForCppRuntime +fun ThrowKotlinNothingValueException(): Nothing { + throw KotlinNothingValueException() +} + @ExportForCppRuntime fun ThrowInvalidReceiverTypeException(klass: KClass<*>): Nothing { throw RuntimeException("Unexpected receiver type: " + (klass.qualifiedName ?: "noname"))