diff --git a/kotlin-native/backend.native/tests/build.gradle b/kotlin-native/backend.native/tests/build.gradle index af8777a1ffb..5c2a164f84c 100644 --- a/kotlin-native/backend.native/tests/build.gradle +++ b/kotlin-native/backend.native/tests/build.gradle @@ -4387,6 +4387,9 @@ if (PlatformInfo.isAppleTarget(project)) { it.defFile 'interop/objc/kt48816/objclib.def' it.headers "$projectDir/interop/objc/kt48816/objclib.h" } + createInterop("objc_kt50648") { + it.defFile 'interop/objc/kt50648/objclib.def' + } } createInterop("withSpaces") { @@ -5033,6 +5036,16 @@ if (PlatformInfo.isAppleTarget(project)) { flags = ["-Xlazy-ir-for-caches=enable"] } + interopTest("interop_objc_kt50648") { + source = 'interop/objc/kt50648/main.kt' + interop = "objc_kt50648" + expectedExitStatusChecker = { it != 0 } + outputChecker = { + it.contains("Converting Obj-C blocks with non-reference-typed return value to kotlin.Any is not supported (v)") && + (it.contains("kfun:#main(){}") || project.globalTestArgs.contains('-opt')) // Stacktrace. + } + } + standaloneTest("objc_arc_contract") { doBeforeBuild { mkdir(buildDir) diff --git a/kotlin-native/backend.native/tests/interop/objc/kt50648/main.kt b/kotlin-native/backend.native/tests/interop/objc/kt50648/main.kt new file mode 100644 index 00000000000..10667664aeb --- /dev/null +++ b/kotlin-native/backend.native/tests/interop/objc/kt50648/main.kt @@ -0,0 +1,5 @@ +import objclib.* + +fun main() { + getVoidBlockAsId() +} diff --git a/kotlin-native/backend.native/tests/interop/objc/kt50648/objclib.def b/kotlin-native/backend.native/tests/interop/objc/kt50648/objclib.def new file mode 100644 index 00000000000..cf0f0555b60 --- /dev/null +++ b/kotlin-native/backend.native/tests/interop/objc/kt50648/objclib.def @@ -0,0 +1,6 @@ +language = Objective-C +--- +id getVoidBlockAsId() { + void (^result)(void) = ^{}; + return result; +} diff --git a/kotlin-native/runtime/src/main/cpp/ObjCExport.mm b/kotlin-native/runtime/src/main/cpp/ObjCExport.mm index a9f63a1947c..a22b4e70291 100644 --- a/kotlin-native/runtime/src/main/cpp/ObjCExport.mm +++ b/kotlin-native/runtime/src/main/cpp/ObjCExport.mm @@ -566,11 +566,13 @@ extern "C" id Kotlin_ObjCExport_refToLocalObjC(ObjHeader* obj) { return Kotlin_ObjCExport_refToObjCImpl(obj); } -extern "C" ALWAYS_INLINE id Kotlin_Interop_refToObjC(ObjHeader* obj) { +// The function is marked with noexcept, so any exception reaching it will cause std::terminate. +extern "C" ALWAYS_INLINE id Kotlin_Interop_refToObjC(ObjHeader* obj) noexcept { return Kotlin_ObjCExport_refToObjCImpl(obj); } -extern "C" ALWAYS_INLINE OBJ_GETTER(Kotlin_Interop_refFromObjC, id obj) { +// The function is marked with noexcept, so any exception reaching it will cause std::terminate. +extern "C" ALWAYS_INLINE OBJ_GETTER(Kotlin_Interop_refFromObjC, id obj) noexcept { // TODO: consider removing this function. RETURN_RESULT_OF(Kotlin_ObjCExport_refFromObjC, obj); }