Always produce nullable type for result out parameter in Obj-C header
Otherwise it would be unusable when passing reference to local variable from Swift as it would require a non-null initializer then.
This commit is contained in:
committed by
SvyatoslavScherbina
parent
fba4a35d60
commit
87396c6caf
+8
-3
@@ -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\"")
|
||||
|
||||
+8
@@ -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
|
||||
}
|
||||
|
||||
@@ -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))
|
||||
|
||||
Reference in New Issue
Block a user