diff --git a/glfw/src/Cursor.zig b/glfw/src/Cursor.zig index 728340e4..ed089aa6 100644 --- a/glfw/src/Cursor.zig +++ b/glfw/src/Cursor.zig @@ -65,7 +65,7 @@ pub inline fn create(image: Image, xhot: isize, yhot: isize) error{ PlatformErro const img = image.toC(); const cursor = c.glfwCreateCursor(&img, @intCast(c_int, xhot), @intCast(c_int, yhot)); getError() catch |err| return switch (err) { - Error.PlatformError => err, + Error.PlatformError => @errSetCast(error{ PlatformError }, err), else => unreachable, }; return Cursor{ .ptr = cursor.? }; @@ -86,7 +86,7 @@ pub inline fn createStandard(shape: Shape) error{ InvalidEnum, PlatformError }!C getError() catch |err| return switch (err) { // TODO: should be impossible given that only the values in 'Shape' are available, unless the user explicitly gives us a bad value via casting Error.InvalidEnum => unreachable, - Error.PlatformError => err, + Error.PlatformError => @errSetCast(error{ PlatformError }, err), else => unreachable, }; return Cursor{ .ptr = cursor.? }; diff --git a/glfw/src/Joystick.zig b/glfw/src/Joystick.zig index 7ac1512f..21e06f98 100644 --- a/glfw/src/Joystick.zig +++ b/glfw/src/Joystick.zig @@ -92,7 +92,7 @@ pub inline fn present(self: Joystick) error{ InvalidEnum, PlatformError }!bool { getError() catch |err| return switch (err) { Error.InvalidEnum, Error.PlatformError, - => err, + => @errSetCast(error{ InvalidEnum, PlatformError }, err), else => unreachable, }; return is_present == c.GLFW_TRUE; @@ -125,7 +125,7 @@ pub inline fn getAxes(self: Joystick) error{ InvalidEnum, PlatformError }!?[]con getError() catch |err| return switch (err) { Error.InvalidEnum, Error.PlatformError, - => err, + => @errSetCast(error{ InvalidEnum, PlatformError }, err), else => unreachable, }; if (axes == null) return null; @@ -163,7 +163,7 @@ pub inline fn getButtons(self: Joystick) error{ InvalidEnum, PlatformError }!?[] getError() catch |err| return switch (err) { Error.InvalidEnum, Error.PlatformError, - => err, + => @errSetCast(error{ InvalidEnum, PlatformError }, err), else => unreachable, }; if (buttons == null) return null; @@ -217,7 +217,7 @@ pub inline fn getHats(self: Joystick) error{ InvalidEnum, PlatformError }!?[]con getError() catch |err| return switch (err) { Error.InvalidEnum, Error.PlatformError, - => err, + => @errSetCast(error{ InvalidEnum, PlatformError }, err), else => unreachable, }; if (hats == null) return null; @@ -250,7 +250,7 @@ pub inline fn getName(self: Joystick) error{ InvalidEnum, PlatformError }!?[:0]c getError() catch |err| return switch (err) { Error.InvalidEnum, Error.PlatformError, - => err, + => @errSetCast(error{ InvalidEnum, PlatformError }, err), else => unreachable, }; return if (name_opt) |name| @@ -292,7 +292,7 @@ pub inline fn getGUID(self: Joystick) error{ InvalidEnum, PlatformError }!?[:0]c getError() catch |err| return switch (err) { Error.InvalidEnum, Error.PlatformError, - => err, + => @errSetCast(error{ InvalidEnum, PlatformError }, err), else => unreachable, }; return if (guid_opt) |guid| @@ -408,7 +408,7 @@ pub inline fn updateGamepadMappings(gamepad_mappings: [*:0]const u8) error{ Inva internal_debug.assertInitialized(); _ = c.glfwUpdateGamepadMappings(gamepad_mappings); getError() catch |err| return switch (err) { - Error.InvalidValue => err, + Error.InvalidValue => @errSetCast(error{ InvalidValue }, err), else => unreachable, }; } @@ -466,7 +466,7 @@ pub inline fn getGamepadName(self: Joystick) error{ InvalidEnum }!?[:0]const u8 internal_debug.assertInitialized(); const name_opt = c.glfwGetGamepadName(self.jid); getError() catch |err| return switch (err) { - Error.InvalidEnum => err, + Error.InvalidEnum => @errSetCast(error{ InvalidEnum }, err), else => unreachable, }; return if (name_opt) |name| @@ -504,7 +504,7 @@ pub inline fn getGamepadState(self: Joystick) error{ InvalidEnum }!?GamepadState var state: GamepadState = undefined; const success = c.glfwGetGamepadState(self.jid, @ptrCast(*c.GLFWgamepadstate, &state)); getError() catch |err| return switch (err) { - Error.InvalidEnum => err, + Error.InvalidEnum => @errSetCast(error{ InvalidEnum }, err), else => unreachable, }; return if (success == c.GLFW_TRUE) state else null; diff --git a/glfw/src/Monitor.zig b/glfw/src/Monitor.zig index 904b1fe2..dfc17eaf 100644 --- a/glfw/src/Monitor.zig +++ b/glfw/src/Monitor.zig @@ -38,7 +38,7 @@ pub inline fn getPos(self: Monitor) error{ PlatformError }!Pos { var ypos: c_int = 0; c.glfwGetMonitorPos(self.handle, &xpos, &ypos); getError() catch |err| return switch (err) { - Error.PlatformError => err, + Error.PlatformError => @errSetCast(error{ PlatformError }, err), else => unreachable, }; return Pos{ .x = @intCast(usize, xpos), .y = @intCast(usize, ypos) }; @@ -72,7 +72,7 @@ pub inline fn getWorkarea(self: Monitor) error{ PlatformError }!Workarea { var height: c_int = 0; c.glfwGetMonitorWorkarea(self.handle, &xpos, &ypos, &width, &height); getError() catch |err| return switch (err) { - Error.PlatformError => err, + Error.PlatformError => @errSetCast(error{ PlatformError }, err), else => unreachable, }; return Workarea{ .x = @intCast(usize, xpos), .y = @intCast(usize, ypos), .width = @intCast(usize, width), .height = @intCast(usize, height) }; @@ -137,7 +137,7 @@ pub inline fn getContentScale(self: Monitor) error{ PlatformError }!ContentScale var y_scale: f32 = 0; c.glfwGetMonitorContentScale(self.handle, &x_scale, &y_scale); getError() catch |err| return switch (err) { - Error.PlatformError => err, + Error.PlatformError => @errSetCast(error{ PlatformError }, err), else => unreachable, }; return ContentScale{ .x_scale = @floatCast(f32, x_scale), .y_scale = @floatCast(f32, y_scale) }; @@ -224,7 +224,7 @@ pub inline fn getVideoModes(self: Monitor, allocator: *mem.Allocator) (mem.Alloc var count: c_int = 0; const modes = c.glfwGetVideoModes(self.handle, &count); getError() catch |err| return switch (err) { - Error.PlatformError => err, + Error.PlatformError => @errSetCast(error{ PlatformError }, err), else => unreachable, }; @@ -251,7 +251,7 @@ pub inline fn getVideoMode(self: Monitor) error{ PlatformError }!VideoMode { internal_debug.assertInitialized(); const mode = c.glfwGetVideoMode(self.handle); getError() catch |err| return switch (err) { - Error.PlatformError => err, + Error.PlatformError => @errSetCast(error{ PlatformError }, err), else => unreachable, }; return VideoMode{ .handle = mode.?.* }; @@ -283,7 +283,7 @@ pub inline fn setGamma(self: Monitor, gamma: f32) error{ InvalidValue, PlatformE // TODO: Consider whether to assert that 'gamma' is a valid value instead of leaving it to GLFW's error handling. Error.InvalidValue, Error.PlatformError, - => err, + => @errSetCast(error{ InvalidValue, PlatformError }, err), else => unreachable, }; } @@ -307,7 +307,7 @@ pub inline fn getGammaRamp(self: Monitor) error{ PlatformError }!GammaRamp { internal_debug.assertInitialized(); const ramp = c.glfwGetGammaRamp(self.handle); getError() catch |err| return switch (err) { - Error.PlatformError => err, + Error.PlatformError => @errSetCast(error{ PlatformError }, err), else => unreachable, }; return GammaRamp.fromC(ramp.*); @@ -342,7 +342,7 @@ pub inline fn setGammaRamp(self: Monitor, ramp: GammaRamp) error{ PlatformError internal_debug.assertInitialized(); c.glfwSetGammaRamp(self.handle, &ramp.toC()); getError() catch |err| return switch (err) { - Error.PlatformError => err, + Error.PlatformError => @errSetCast(error{ PlatformError }, err), else => unreachable, }; } diff --git a/glfw/src/Window.zig b/glfw/src/Window.zig index 78be67fb..2b72abe6 100644 --- a/glfw/src/Window.zig +++ b/glfw/src/Window.zig @@ -505,7 +505,7 @@ pub inline fn setTitle(self: Window, title: [*:0]const u8) error{ PlatformError internal_debug.assertInitialized(); c.glfwSetWindowTitle(self.handle, title); getError() catch |err| return switch (err) { - Error.PlatformError => err, + Error.PlatformError => @errSetCast(error{ PlatformError }, err), else => unreachable, }; } @@ -547,7 +547,7 @@ pub inline fn setIcon(self: Window, allocator: *mem.Allocator, images: ?[]Image) c.glfwSetWindowIcon(self.handle, @intCast(c_int, im.len), &tmp[0]); } else c.glfwSetWindowIcon(self.handle, 0, null); getError() catch |err| return switch (err) { - Error.PlatformError => err, + Error.PlatformError => @errSetCast(error{ PlatformError }, err), else => unreachable, }; } @@ -576,7 +576,7 @@ pub inline fn getPos(self: Window) error{ PlatformError }!Pos { var y: c_int = 0; c.glfwGetWindowPos(self.handle, &x, &y); getError() catch |err| return switch (err) { - Error.PlatformError => err, + Error.PlatformError => @errSetCast(error{ PlatformError }, err), else => unreachable, }; return Pos{ .x = @intCast(usize, x), .y = @intCast(usize, y) }; @@ -606,7 +606,7 @@ pub inline fn setPos(self: Window, pos: Pos) error{ PlatformError }!void { internal_debug.assertInitialized(); c.glfwSetWindowPos(self.handle, @intCast(c_int, pos.x), @intCast(c_int, pos.y)); getError() catch |err| return switch (err) { - Error.PlatformError => err, + Error.PlatformError => @errSetCast(error{ PlatformError }, err), else => unreachable, }; } @@ -633,7 +633,7 @@ pub inline fn getSize(self: Window) error{ PlatformError }!Size { var height: c_int = 0; c.glfwGetWindowSize(self.handle, &width, &height); getError() catch |err| return switch (err) { - Error.PlatformError => err, + Error.PlatformError => @errSetCast(error{ PlatformError }, err), else => unreachable, }; return Size{ .width = @intCast(usize, width), .height = @intCast(usize, height) }; @@ -665,7 +665,7 @@ pub inline fn setSize(self: Window, size: Size) error{ PlatformError }!void { internal_debug.assertInitialized(); c.glfwSetWindowSize(self.handle, @intCast(c_int, size.width), @intCast(c_int, size.height)); getError() catch |err| return switch (err) { - Error.PlatformError => err, + Error.PlatformError => @errSetCast(error{ PlatformError }, err), else => unreachable, }; } @@ -703,7 +703,7 @@ pub inline fn setSizeLimits(self: Window, min: Size, max: Size) error{ InvalidVa getError() catch |err| return switch (err) { Error.InvalidValue, Error.PlatformError, - => err, + => @errSetCast(error{ InvalidValue, PlatformError }, err), else => unreachable, }; } @@ -740,7 +740,7 @@ pub inline fn setAspectRatio(self: Window, numerator: usize, denominator: usize) getError() catch |err| return switch (err) { Error.InvalidValue, Error.PlatformError, - => err, + => @errSetCast(error{ InvalidValue, PlatformError }, err), else => unreachable, }; } @@ -761,7 +761,7 @@ pub inline fn getFramebufferSize(self: Window) error{ PlatformError }!Size { var height: c_int = 0; c.glfwGetFramebufferSize(self.handle, &width, &height); getError() catch |err| return switch (err) { - Error.PlatformError => err, + Error.PlatformError => @errSetCast(error{ PlatformError }, err), else => unreachable, }; return Size{ .width = @intCast(usize, width), .height = @intCast(usize, height) }; @@ -796,7 +796,7 @@ pub inline fn getFrameSize(self: Window) error{ PlatformError }!FrameSize { var bottom: c_int = 0; c.glfwGetWindowFrameSize(self.handle, &left, &top, &right, &bottom); getError() catch |err| return switch (err) { - Error.PlatformError => err, + Error.PlatformError => @errSetCast(error{ PlatformError }, err), else => unreachable, }; return FrameSize{ @@ -835,7 +835,7 @@ pub inline fn getContentScale(self: Window) error{ PlatformError }!ContentScale var y_scale: f32 = 0; c.glfwGetWindowContentScale(self.handle, &x_scale, &y_scale); getError() catch |err| return switch (err) { - Error.PlatformError => err, + Error.PlatformError => @errSetCast(error{ PlatformError }, err), else => unreachable, }; return ContentScale{ .x_scale = x_scale, .y_scale = y_scale }; @@ -860,7 +860,7 @@ pub inline fn getOpacity(self: Window) error{ PlatformError }!f32 { internal_debug.assertInitialized(); const opacity = c.glfwGetWindowOpacity(self.handle); getError() catch |err| return switch (err) { - Error.PlatformError => err, + Error.PlatformError => @errSetCast(error{ PlatformError }, err), else => unreachable, }; return opacity; @@ -887,7 +887,7 @@ pub inline fn setOpacity(self: Window, opacity: f32) error{ PlatformError }!void internal_debug.assertInitialized(); c.glfwSetWindowOpacity(self.handle, opacity); getError() catch |err| return switch (err) { - Error.PlatformError => err, + Error.PlatformError => @errSetCast(error{ PlatformError }, err), else => unreachable, }; } @@ -912,7 +912,7 @@ pub inline fn iconify(self: Window) error{ PlatformError }!void { internal_debug.assertInitialized(); c.glfwIconifyWindow(self.handle); getError() catch |err| return switch (err) { - Error.PlatformError => err, + Error.PlatformError => @errSetCast(error{ PlatformError }, err), else => unreachable, }; } @@ -934,7 +934,7 @@ pub inline fn restore(self: Window) error{ PlatformError }!void { internal_debug.assertInitialized(); c.glfwRestoreWindow(self.handle); getError() catch |err| return switch (err) { - Error.PlatformError => err, + Error.PlatformError => @errSetCast(error{ PlatformError }, err), else => unreachable, }; } @@ -955,7 +955,7 @@ pub inline fn maximize(self: Window) error{ PlatformError }!void { internal_debug.assertInitialized(); c.glfwMaximizeWindow(self.handle); getError() catch |err| return switch (err) { - Error.PlatformError => err, + Error.PlatformError => @errSetCast(error{ PlatformError }, err), else => unreachable, }; } @@ -978,7 +978,7 @@ pub inline fn show(self: Window) error{ PlatformError }!void { internal_debug.assertInitialized(); c.glfwShowWindow(self.handle); getError() catch |err| return switch (err) { - Error.PlatformError => err, + Error.PlatformError => @errSetCast(error{ PlatformError }, err), else => unreachable, }; } @@ -997,7 +997,7 @@ pub inline fn hide(self: Window) error{ PlatformError }!void { internal_debug.assertInitialized(); c.glfwHideWindow(self.handle); getError() catch |err| return switch (err) { - Error.PlatformError => err, + Error.PlatformError => @errSetCast(error{ PlatformError }, err), else => unreachable, }; } @@ -1030,7 +1030,7 @@ pub inline fn focus(self: Window) error{ PlatformError }!void { internal_debug.assertInitialized(); c.glfwFocusWindow(self.handle); getError() catch |err| return switch (err) { - Error.PlatformError => err, + Error.PlatformError => @errSetCast(error{ PlatformError }, err), else => unreachable, }; } @@ -1054,7 +1054,7 @@ pub inline fn requestAttention(self: Window) error{ PlatformError }!void { internal_debug.assertInitialized(); c.glfwRequestWindowAttention(self.handle); getError() catch |err| return switch (err) { - Error.PlatformError => err, + Error.PlatformError => @errSetCast(error{ PlatformError }, err), else => unreachable, }; } @@ -1086,7 +1086,7 @@ pub inline fn swapBuffers(self: Window) error{ NoWindowContext, PlatformError }! getError() catch |err| return switch (err) { Error.NoWindowContext, Error.PlatformError, - => err, + => @errSetCast(error{ NoWindowContext, PlatformError }, err), else => unreachable, }; } @@ -1165,7 +1165,7 @@ pub inline fn setMonitor(self: Window, monitor: ?Monitor, xpos: isize, ypos: isi @intCast(c_int, refresh_rate), ); getError() catch |err| return switch (err) { - Error.PlatformError => err, + Error.PlatformError => @errSetCast(error{ PlatformError }, err), else => unreachable, }; } @@ -1224,7 +1224,7 @@ pub inline fn getAttrib(self: Window, attrib: Attrib) error{ InvalidEnum, Platfo getError() catch |err| return switch (err) { Error.InvalidEnum, Error.PlatformError, - => err, + => @errSetCast(error{ InvalidEnum, PlatformError }, err), else => unreachable, }; return v; @@ -1262,7 +1262,7 @@ pub inline fn setAttrib(self: Window, attrib: Attrib, value: bool) error{ Invali Error.InvalidEnum, Error.InvalidValue, Error.PlatformError, - => err, + => @errSetCast(error{ InvalidEnum, InvalidValue, PlatformError }, err), else => unreachable, }; } @@ -1748,7 +1748,7 @@ pub inline fn setInputMode(self: Window, mode: InputMode, value: anytype) error{ getError() catch |err| return switch (err) { Error.InvalidEnum, Error.PlatformError, - => err, + => @errSetCast(error{ InvalidEnum, PlatformError }, err), else => unreachable, }; } @@ -1783,7 +1783,7 @@ pub inline fn getKey(self: Window, key: Key) error{ InvalidEnum }!Action { internal_debug.assertInitialized(); const state = c.glfwGetKey(self.handle, @enumToInt(key)); getError() catch |err| return switch (err) { - Error.InvalidEnum => err, + Error.InvalidEnum => @errSetCast(error{ InvalidEnum }, err), else => unreachable, }; return @intToEnum(Action, state); @@ -1809,7 +1809,7 @@ pub inline fn getMouseButton(self: Window, button: MouseButton) error{ InvalidEn internal_debug.assertInitialized(); const state = c.glfwGetMouseButton(self.handle, @enumToInt(button)); getError() catch |err| return switch (err) { - Error.InvalidEnum => err, + Error.InvalidEnum => @errSetCast(error{ InvalidEnum }, err), else => unreachable, }; return @intToEnum(Action, state); @@ -1850,7 +1850,7 @@ pub inline fn getCursorPos(self: Window) error{ PlatformError }!CursorPos { var pos: CursorPos = undefined; c.glfwGetCursorPos(self.handle, &pos.xpos, &pos.ypos); getError() catch |err| return switch (err) { - Error.PlatformError => err, + Error.PlatformError => @errSetCast(error{ PlatformError }, err), else => unreachable, }; return pos; @@ -1885,7 +1885,7 @@ pub inline fn setCursorPos(self: Window, xpos: f64, ypos: f64) error{ PlatformEr internal_debug.assertInitialized(); c.glfwSetCursorPos(self.handle, xpos, ypos); getError() catch |err| return switch (err) { - Error.PlatformError => err, + Error.PlatformError => @errSetCast(error{ PlatformError }, err), else => unreachable, }; } @@ -1909,7 +1909,7 @@ pub inline fn setCursor(self: Window, cursor: Cursor) error{ PlatformError }!voi internal_debug.assertInitialized(); c.glfwSetCursor(self.handle, cursor.ptr); getError() catch |err| return switch (err) { - Error.PlatformError => err, + Error.PlatformError => @errSetCast(error{ PlatformError }, err), else => unreachable, }; } diff --git a/glfw/src/clipboard.zig b/glfw/src/clipboard.zig index 985ad463..7f4c671c 100644 --- a/glfw/src/clipboard.zig +++ b/glfw/src/clipboard.zig @@ -23,7 +23,7 @@ pub inline fn setClipboardString(value: [*:0]const u8) error{ PlatformError }!vo internal_debug.assertInitialized(); c.glfwSetClipboardString(null, value); getError() catch |err| return switch (err) { - Error.PlatformError => err, + Error.PlatformError => @errSetCast(error{ PlatformError }, err), else => unreachable, }; } @@ -49,7 +49,7 @@ pub inline fn getClipboardString() error{ PlatformError }![:0]const u8 { internal_debug.assertInitialized(); const value = c.glfwGetClipboardString(null); getError() catch |err| return switch (err) { - Error.PlatformError => err, + Error.PlatformError => @errSetCast(error{ PlatformError }, err), else => unreachable, }; return std.mem.span(value); diff --git a/glfw/src/key.zig b/glfw/src/key.zig index fd49b463..a92bc94a 100644 --- a/glfw/src/key.zig +++ b/glfw/src/key.zig @@ -218,7 +218,7 @@ pub const Key = enum(c_int) { internal_debug.assertInitialized(); const name_opt = cc.glfwGetKeyName(@enumToInt(self), @intCast(c_int, scancode)); getError() catch |err| return switch (err) { - Error.PlatformError => err, + Error.PlatformError => @errSetCast(error{ PlatformError }, err), else => unreachable, }; return if (name_opt) |name| @@ -244,7 +244,7 @@ pub const Key = enum(c_int) { const scancode = cc.glfwGetKeyScancode(@enumToInt(self)); getError() catch |err| return switch (err) { Error.InvalidEnum => unreachable, // Should be unreachable for any valid 'Key' value. - Error.PlatformError => err, + Error.PlatformError => @errSetCast(error{ PlatformError }, err), else => unreachable, }; return scancode; diff --git a/glfw/src/main.zig b/glfw/src/main.zig index 13dac900..8412f484 100644 --- a/glfw/src/main.zig +++ b/glfw/src/main.zig @@ -68,8 +68,7 @@ pub inline fn init(hints: InitHints) error{ PlatformError }!void { initHint(init_hint, init_value) catch |err| switch (err) { // TODO: Consider this; should not be reachable, given that all of the hint tags and hint values // are coming in from a strict set of predefined values in 'InitHints' and 'InitHint' - Error.InvalidValue, - Error.InvalidEnum, + error.InvalidValue, => unreachable, else => unreachable, }; @@ -77,7 +76,7 @@ pub inline fn init(hints: InitHints) error{ PlatformError }!void { _ = c.glfwInit(); getError() catch |err| return switch (err) { - Error.PlatformError => err, + Error.PlatformError => @errSetCast(error{ PlatformError }, err), else => unreachable, }; } @@ -182,7 +181,7 @@ fn initHint(hint: InitHint, value: anytype) error{ InvalidValue }!void { } getError() catch |err| return switch (err) { Error.InvalidEnum => unreachable, // impossible for any valid 'InitHint' value - Error.InvalidValue => err, + Error.InvalidValue => @errSetCast(error{ InvalidValue }, err), else => unreachable, }; } @@ -238,7 +237,7 @@ pub inline fn pollEvents() error{ PlatformError }!void { internal_debug.assertInitialized(); c.glfwPollEvents(); getError() catch |err| return switch (err) { - Error.PlatformError => err, + Error.PlatformError => @errSetCast(error{ PlatformError }, err), else => unreachable, }; } @@ -277,7 +276,7 @@ pub inline fn waitEvents() error{ PlatformError }!void { internal_debug.assertInitialized(); c.glfwWaitEvents(); getError() catch |err| return switch (err) { - Error.PlatformError => err, + Error.PlatformError => @errSetCast(error{ PlatformError }, err), else => unreachable, }; } @@ -324,7 +323,7 @@ pub inline fn waitEventsTimeout(timeout: f64) error{ InvalidValue, PlatformError // and make its branch unreachable. Error.InvalidValue, Error.PlatformError, - => err, + => @errSetCast(error{ InvalidValue, PlatformError }, err), else => unreachable, }; } @@ -343,7 +342,7 @@ pub inline fn postEmptyEvent() error{ PlatformError }!void { internal_debug.assertInitialized(); c.glfwPostEmptyEvent(); getError() catch |err| return switch (err) { - Error.PlatformError => err, + Error.PlatformError => @errSetCast(error{ PlatformError }, err), else => unreachable, }; } diff --git a/glfw/src/opengl.zig b/glfw/src/opengl.zig index 3648ffe3..8507352c 100644 --- a/glfw/src/opengl.zig +++ b/glfw/src/opengl.zig @@ -37,7 +37,7 @@ pub inline fn makeContextCurrent(window: ?Window) error{ NoWindowContext, Platfo getError() catch |err| return switch (err) { Error.NoWindowContext, Error.PlatformError, - => err, + => @errSetCast(error{ NoWindowContext, PlatformError }, err), else => unreachable, }; } @@ -54,8 +54,7 @@ pub inline fn makeContextCurrent(window: ?Window) error{ NoWindowContext, Platfo /// @thread_safety This function may be called from any thread. /// /// see also: context_current, glfwMakeContextCurrent -// TODO: Remove error stub -pub inline fn getCurrentContext() error{}!?Window { +pub inline fn getCurrentContext() std.mem.Allocator.Error!?Window { internal_debug.assertInitialized(); const handle = c.glfwGetCurrentContext(); getError() catch unreachable; // Only error 'GLFW_NOT_INITIALIZED' is impossible @@ -102,7 +101,7 @@ pub inline fn swapInterval(interval: isize) error{ NoCurrentContext, PlatformErr getError() catch |err| return switch (err) { Error.NoCurrentContext, Error.PlatformError, - => err, + => @errSetCast(error{ NoCurrentContext, PlatformError }, err), else => unreachable, }; } @@ -138,7 +137,7 @@ pub inline fn extensionSupported(extension: [*:0]const u8) error{ NoCurrentConte getError() catch |err| return switch (err) { Error.NoCurrentContext, Error.InvalidValue, - => err, + => @errSetCast(error{ NoCurrentContext, InvalidValue }, err), else => unreachable, }; return supported == c.GLFW_TRUE; diff --git a/glfw/src/time.zig b/glfw/src/time.zig index 833f4ca9..1a22f3c8 100644 --- a/glfw/src/time.zig +++ b/glfw/src/time.zig @@ -58,7 +58,7 @@ pub inline fn setTime(time: f64) error{ InvalidValue }!void { c.glfwSetTime(time); getError() catch |err| return switch (err) { // TODO: Consider whether to use GLFW error handling, or assert that 'time' is a valid value - Error.InvalidValue => err, + Error.InvalidValue => @errSetCast(error{ InvalidValue }, err), else => unreachable, }; } diff --git a/glfw/src/vulkan.zig b/glfw/src/vulkan.zig index 08433a4f..6bb62a80 100644 --- a/glfw/src/vulkan.zig +++ b/glfw/src/vulkan.zig @@ -66,7 +66,7 @@ pub inline fn getRequiredInstanceExtensions() error{ APIUnavailable }![][*:0]con var count: u32 = 0; const extensions = c.glfwGetRequiredInstanceExtensions(&count); getError() catch |err| return switch (err) { - Error.APIUnavailable => err, + Error.APIUnavailable => @errSetCast(error{ APIUnavailable }, err), else => unreachable, }; return @ptrCast([*][*:0]const u8, extensions)[0..count]; @@ -153,7 +153,7 @@ pub inline fn getPhysicalDevicePresentationSupport(vk_instance: *opaque {}, vk_p getError() catch |err| return switch (err) { Error.APIUnavailable, Error.PlatformError, - => err, + => @errSetCast(error{ APIUnavailable, PlatformError }, err), else => unreachable, }; return v == c.GLFW_TRUE;