You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
+1 same issue here. I'm using Zig 0.15.1 with branch zig-0.15.1 (master branch also doesn't work). I'm on x86_64 linux. Looks like CI caught the issue a few commits ago, but it hasn't been noticed/fixed yet. Last known working version: be8b496
EDIT: Last known working version doesn't have support for zig 0.15.1
UPDATE: I found that building with --release=safe (or -Doptimize=ReleaseSafe; also fast release) works as expected. The issue only appears with -Doptimize=Debug
I comment-traced the Db.exec to Statement.bind, and I think the problem (or at least a problem) is that with the above example, query doesn't have expected fields:
/// bind binds values to every bind marker in the prepared statement.
///
/// The `values` variable must be a struct where each field has the type of the corresponding bind marker.
/// For example this query:
/// SELECT 1 FROM user WHERE name = ?{text} AND age < ?{u32}
///
/// Has two bind markers, so `values` must have at least the following fields:
/// struct {
/// name: Text,
/// age: u32
/// }
///
/// The types are checked at comptime.
fn bind(self: *Self, options: anytype, values: anytype) !void {
// smlavine
_ = &self;
_ = &options;
_ = &values;
const StructType = @TypeOf(values);
if (!comptime isStruct(StructType)) {
@compileError("options passed to Statement.bind must be a struct (DynamicStatement supports runtime slices)");
}
const StructTypeInfo = @typeInfo(StructType).@"struct";
_ = &StructTypeInfo;
comptime marker_len_check: {
// problem is with `query.bind_markers.len` expression
@compileLog(@hasField(query, "bind_markers"));
break :marker_len_check;
//if (query.bind_markers.len != StructTypeInfo.fields.len) {
// break :marker_len_check;
// //if (query.bind_markers.len > StructTypeInfo.fields.len) {
// // var found_markers = 0;
// // for (query.bind_markers) |bind_marker| {
// // if (bind_marker.name) |name| {
// // if (@hasField(StructType, name)) {
// // found_markers += 1;
// // }
// // }
// // }
// // if (found_markers == query.bind_markers.len) {
// // break :marker_len_check;
// // }
// //}
// //@compileError(std.fmt.comptimePrint("expected {d} bind parameters but got {d}", .{
// // query.bind_markers.len,
// // StructTypeInfo.fields.len,
// //}));
//}
}
//inline for (StructTypeInfo.fields, 0..) |struct_field, _i| {
// const bind_marker = query.bind_markers[_i];
// if (bind_marker.typed) |typ| {
// const FieldTypeInfo = @typeInfo(struct_field.type);
// switch (FieldTypeInfo) {
// .@"struct", .@"enum", .@"union" => comptime assertMarkerType(
// if (@hasDecl(struct_field.type, "BaseType")) struct_field.type.BaseType else struct_field.type,
// typ,
// ),
// else => comptime assertMarkerType(struct_field.type, typ),
// }
// }
//}
//return self.dynamic().bind(options, values) catch |e| switch (e) {
// errors.Error.SQLiteNotFound => unreachable, // impossible to have non-existent field
// else => e,
//};
}
Gives compiler output
Compile Log Output:
@as(bool, false)
The above compile log output does not change with .use_llvm = true, but the compiler does not crash or error out.
Activity
tadejg commentedon Aug 29, 2025
+1 same issue here. I'm using Zig 0.15.1 with branch zig-0.15.1 (master branch also doesn't work). I'm on x86_64 linux. Looks like CI caught the issue a few commits ago, but it hasn't been noticed/fixed yet. Last known working version: be8b496
EDIT: Last known working version doesn't have support for zig 0.15.1
vrischmann commentedon Aug 29, 2025
https://github.com/vrischmann/zig-sqlite-demo works fine with zig 0.15.1; please create a reproducer that I can easily clone and test myself, I can't help you with just this report.
tadejg commentedon Aug 29, 2025
This demo app also fails to compile for me
tadejg commentedon Aug 29, 2025
UPDATE: I found that building with
--release=safe(or-Doptimize=ReleaseSafe; also fast release) works as expected. The issue only appears with-Doptimize=Debugtadejg commentedon Aug 29, 2025
@vrischmann if it helps, here's a Dockerfile which reproduces the issue.
Output
enverbisevac commentedon Aug 29, 2025
Yes it works for me too with --release=safe
tadejg commentedon Aug 30, 2025
@vrischmann I also noticed you switched to dynamic linking for 0.15.1. What was the reasoning behind that? I'd prefer to keep it static, if possible.
vrischmann commentedon Aug 30, 2025
So, there was no reason to change to dynamic linking, that was an oversight when merging a PR.
But that is not the issue here, executing the
zig build-execommand shows zig crashing:Seems to only affect Linux, on macOS it builds fine.
tadejg commentedon Aug 30, 2025
Maybe related to ziglang/zig#25060
Adding
.use_llvm = trueto the demobuild.zigseems to workvrischmann commentedon Aug 30, 2025
I rebuilt zig myself because the version installed with zvm does not have debug symbols, now I see this:
Looks like a bug in the compiler which I can't do much about unfortunately.
vrischmann commentedon Aug 30, 2025
Nice find, the stack trace looks the same.
enverbisevac commentedon Aug 30, 2025
Thanks @tadejg, @vrischmann , works with .use_llvm = true
Koeng101 commentedon Sep 27, 2025
Have you reported it to zig? I ran into this error as well, so hopefully reporting could get a fix in the queue.
chung-leong commentedon Nov 11, 2025
I see that the linking has been switched back to static on master. Please make the same change in the 0.15.1 branch.
pollend commentedon Dec 26, 2025
I think this is related to comptime. I narrowed it down to db.prepare but im guessing its any type of method processing the sql statement.
use llvm see vrischmann/zig-sqlite#195
smlavine commentedon Jan 7, 2026
I investigated this a bit after running into this issue with a program of mine.
I can reproduce unexpected compiler crash with x86_64 Debug backend, but not with llvm backend.
Example code:
I comment-traced the Db.exec to Statement.bind, and I think the problem (or at least a problem) is that with the above example, query doesn't have expected fields:
Gives compiler output
The above compile log output does not change with
.use_llvm = true, but the compiler does not crash or error out.jozip commentedon Jan 7, 2026
This is fixed in https://codeberg.org/ziglang/zig/pulls/30667 and will be available in a master build soonish