fix return type mismatch when cross-compiling with macos sdk

This commit is contained in:
Mitchell Hashimoto 2023-10-20 15:51:23 -07:00
parent e94d728f47
commit 7110b7c5f2
No known key found for this signature in database
GPG key ID: 523D5DC389D273BC

View file

@ -78,7 +78,14 @@ pub const Class = struct {
// only call this function between allocateClassPair and registerClassPair // only call this function between allocateClassPair and registerClassPair
// this adds an Ivar of type `id`. // this adds an Ivar of type `id`.
pub fn addIvar(self: Class, name: [:0]const u8) bool { pub fn addIvar(self: Class, name: [:0]const u8) bool {
return c.class_addIvar(self.value, name, @sizeOf(c.id), @alignOf(c.id), "@"); // The return type is i8 when we're cross compiling, unsure why.
const fn_info = @typeInfo(@TypeOf(c.class_addIvar)).Fn;
const result = c.class_addIvar(self.value, name, @sizeOf(c.id), @alignOf(c.id), "@");
return switch (fn_info.return_type.?) {
bool => result,
i8 => result == 1,
else => @compileError("unhandled class_addIvar return type"),
};
} }
}; };