From 90e9525b3873a1dad782a25d9cde3565520b9e2b Mon Sep 17 00:00:00 2001 From: Vincent Rischmann Date: Tue, 27 Apr 2021 21:05:10 +0200 Subject: workaround compiler bug This workaround allows one to write this: const Foobar = struct { foo: usize, bar: []const u8, }; const row = try stmt.one(Foobar); Where the first field in the struct (here `foo`) is either an integer type, a float type or a boolean. Moving the first field of this type to second position resolves the bug. This is because readInt, readFloat and readBool have an empty error set and cause this bug to trigger. Removing the error altogether also triggers the bug so we define an explicit error set. If we actually want to return an error from these functions we'll simply remove the workaround. See https://github.com/ziglang/zig/issues/5149 --- sqlite.zig | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'sqlite.zig') diff --git a/sqlite.zig b/sqlite.zig index 097c7a9..cad4a6e 100644 --- a/sqlite.zig +++ b/sqlite.zig @@ -667,19 +667,25 @@ pub fn Iterator(comptime Type: type) type { } // readInt reads a sqlite INTEGER column into an integer. - fn readInt(self: *Self, comptime IntType: type, i: usize) !IntType { + // + // TODO remove the workaround once https://github.com/ziglang/zig/issues/5149 is resolved or if we actually return an error + fn readInt(self: *Self, comptime IntType: type, i: usize) error{Workaround}!IntType { const n = c.sqlite3_column_int64(self.stmt, @intCast(c_int, i)); return @intCast(IntType, n); } // readFloat reads a sqlite REAL column into a float. - fn readFloat(self: *Self, comptime FloatType: type, i: usize) !FloatType { + // + // TODO remove the workaround once https://github.com/ziglang/zig/issues/5149 is resolved or if we actually return an error + fn readFloat(self: *Self, comptime FloatType: type, i: usize) error{Workaround}!FloatType { const d = c.sqlite3_column_double(self.stmt, @intCast(c_int, i)); return @floatCast(FloatType, d); } // readFloat reads a sqlite INTEGER column into a bool (true is anything > 0, false is anything <= 0). - fn readBool(self: *Self, i: usize) !bool { + // + // TODO remove the workaround once https://github.com/ziglang/zig/issues/5149 is resolved or if we actually return an error + fn readBool(self: *Self, i: usize) error{Workaround}!bool { const d = c.sqlite3_column_int64(self.stmt, @intCast(c_int, i)); return d > 0; } -- cgit v1.2.3