zig
zig copied to clipboard
JSON parsing incorrectly in Release* modes
Zig Version
0.10.0-dev.3369+fdaf9c40d
This bug is not present in version 0.9.1.
Steps to Reproduce
const std = @import("std");
const StrangeStruct = struct {
name: ?[]u8 = null, // it works if you remove this field
num: ?i8 = null,
nodes: ?[]StrangeStruct = null, // OR if you remove this one
};
pub fn main() anyerror!void {
var messageBuf: []const u8 = "{\"num\":1}";
var tokens = std.json.TokenStream.init(messageBuf);
const json = try std.json.parse(StrangeStruct, &tokens, .{});
std.log.err("Printing", .{});
if (json.num) |num| {
// should print the number, but doesn't in ReleaseSafe, ReleaseSmall, and ReleaseFast
std.log.err("num {d}", .{num});
}
}
Save to bug.zig and compile with zig build-exe -O ReleaseSafe bug.zig and zig build-exe -O Debug bug.zig
Expected Behavior
I expected the num field to be printed in both Debug and ReleaseFast/Safe/Small modes.
Actual Behavior
The num field is only printed in Debug mode.