diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/objcexport/ObjCExportHeaderGenerator.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/objcexport/ObjCExportHeaderGenerator.kt index edfc1467efd..25e5b34ce45 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/objcexport/ObjCExportHeaderGenerator.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/objcexport/ObjCExportHeaderGenerator.kt @@ -639,8 +639,14 @@ internal class ObjCExportTranslatorImpl( MethodBridgeValueParameter.ErrorOutParameter -> ObjCPointerType(ObjCNullableReferenceType(ObjCClassType("NSError")), nullable = true) - is MethodBridgeValueParameter.KotlinResultOutParameter -> - ObjCPointerType(mapType(method.returnType!!, bridge.bridge, objCExportScope), nullable = true) + is MethodBridgeValueParameter.KotlinResultOutParameter -> { + val resultType = mapType(method.returnType!!, bridge.bridge, objCExportScope) + // Note: non-nullable reference or pointer type is unusable here + // when passing reference to local variable from Swift because it + // would require a non-null initializer then. + val pointeeType = resultType.makeNullableIfReferenceOrPointer() + ObjCPointerType(pointeeType, nullable = true) + } } parameters += ObjCParameter(uniqueName, p, type) @@ -981,7 +987,6 @@ abstract class ObjCExportHeaderGenerator internal constructor( listOf( "-Wunknown-warning-option", "-Wnullability", - "-Wnullability-completeness", "-Wswift-name-attribute" ).forEach { add("#pragma clang diagnostic ignored \"$it\"") diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/objcexport/objcTypes.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/objcexport/objcTypes.kt index 57ea9ad5525..30a3c9785f7 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/objcexport/objcTypes.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/objcexport/objcTypes.kt @@ -130,3 +130,11 @@ internal enum class ObjCValueType(val encoding: String) { DOUBLE("d"), POINTER("^v") } + +internal fun ObjCType.makeNullableIfReferenceOrPointer(): ObjCType = when (this) { + is ObjCPointerType -> ObjCPointerType(this.pointee, nullable = true) + + is ObjCNonNullReferenceType -> ObjCNullableReferenceType(this) + + is ObjCNullableReferenceType, is ObjCRawType, is ObjCPrimitiveType, ObjCVoidType -> this +} diff --git a/backend.native/tests/framework/values/expectedLazy.h b/backend.native/tests/framework/values/expectedLazy.h index dfc10b71fad..29e9862e422 100644 --- a/backend.native/tests/framework/values/expectedLazy.h +++ b/backend.native/tests/framework/values/expectedLazy.h @@ -297,7 +297,7 @@ __attribute__((swift_name("Bridge"))) - (ValuesKotlinNothing * _Nullable)foo1AndReturnError:(NSError * _Nullable * _Nullable)error __attribute__((swift_name("foo1()"))); - (BOOL)foo2AndReturnResult:(int32_t * _Nullable)result error:(NSError * _Nullable * _Nullable)error __attribute__((swift_name("foo2(result:)"))); - (BOOL)foo3AndReturnError:(NSError * _Nullable * _Nullable)error __attribute__((swift_name("foo3()"))); -- (BOOL)foo4AndReturnResult:(ValuesKotlinNothing ** _Nullable)result error:(NSError * _Nullable * _Nullable)error __attribute__((swift_name("foo4(result:)"))); +- (BOOL)foo4AndReturnResult:(ValuesKotlinNothing * _Nullable * _Nullable)result error:(NSError * _Nullable * _Nullable)error __attribute__((swift_name("foo4(result:)"))); @end; __attribute__((objc_subclassing_restricted))