diff --git a/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/objcexport/ObjCExportCodeGenerator.kt b/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/objcexport/ObjCExportCodeGenerator.kt index 825d82046c1..39c31b87612 100644 --- a/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/objcexport/ObjCExportCodeGenerator.kt +++ b/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/objcexport/ObjCExportCodeGenerator.kt @@ -1586,34 +1586,22 @@ internal fun ObjCExportCodeGenerator.getEncoding(methodBridge: MethodBridge): St } } - val targetFamily = context.config.target.family - val returnTypeEncoding = methodBridge.returnBridge.getObjCEncoding(targetFamily) + val returnTypeEncoding = methodBridge.returnBridge.getObjCEncoding(context) val paramSize = paramOffset return "$returnTypeEncoding$paramSize$params" } -// https://developer.apple.com/documentation/objectivec/nsuinteger?language=objc -// `typedef unsigned long NSUInteger` on iOS, macOS, tvOS. -// `typedef unsigned int NSInteger` on watchOS. -private val Family.nsUIntegerEncoding: String get() = when (this) { - Family.OSX, - Family.IOS, - Family.TVOS -> "L" - Family.WATCHOS -> "I" - else -> error("Unexpected target platform: $this") -} - -private fun MethodBridge.ReturnValue.getObjCEncoding(targetFamily: Family): String = when (this) { +private fun MethodBridge.ReturnValue.getObjCEncoding(context: Context): String = when (this) { MethodBridge.ReturnValue.Suspend, MethodBridge.ReturnValue.Void -> "v" - MethodBridge.ReturnValue.HashCode -> targetFamily.nsUIntegerEncoding + MethodBridge.ReturnValue.HashCode -> if (context.is64BitNSInteger()) "L" else "I" is MethodBridge.ReturnValue.Mapped -> this.bridge.objCEncoding MethodBridge.ReturnValue.WithError.Success -> ObjCValueType.BOOL.encoding MethodBridge.ReturnValue.Instance.InitResult, MethodBridge.ReturnValue.Instance.FactoryResult -> ReferenceBridge.objCEncoding - is MethodBridge.ReturnValue.WithError.ZeroForError -> this.successBridge.getObjCEncoding(targetFamily) + is MethodBridge.ReturnValue.WithError.ZeroForError -> this.successBridge.getObjCEncoding(context) } private val MethodBridgeParameter.objCEncoding: String get() = when (this) { diff --git a/kotlin-native/backend.native/tests/interop/objc/smoke.kt b/kotlin-native/backend.native/tests/interop/objc/smoke.kt index b01f0680854..9bcb39c394b 100644 --- a/kotlin-native/backend.native/tests/interop/objc/smoke.kt +++ b/kotlin-native/backend.native/tests/interop/objc/smoke.kt @@ -67,11 +67,12 @@ fun run() { // hashCode (directly): // hash() returns value of NSUInteger type. - val hash = when (Platform.osFamily) { + val hash = if (Platform.osFamily == OsFamily.WATCHOS && Platform.cpuArchitecture.bitness == 32) { // `typedef unsigned int NSInteger` on watchOS. - OsFamily.WATCHOS -> foo.hash().toInt() + foo.hash().toInt() + } else { // `typedef unsigned long NSUInteger` on iOS, macOS, tvOS. - else -> foo.hash().let { it.toInt() xor (it shr 32).toInt() } + foo.hash().let { it.toInt() xor (it shr 32).toInt() } } if (foo.hashCode() == hash) { // toString (virtually):