Zig Version
0.13.0
Steps to Reproduce and Observed Output
I'm writing a graphical formatter that pretty-prints custom Error objects. Note that Error is a struct, not an error union. Be advised, all NOTE comments have been added to this issue but do not exist in my code. They exist solely as clarification.
// NOTE: const Error = @import("Error.zig");
const GraphicalFormatter = struct {
fn format(self: *GraphicalFormatter, w: *std.fs.File.Writer, e: Error) !void {
// NOTE: .message refactored from `[]const u8` to `PossiblyStaticStr`, but
// format string hasn't been changed yet. This is the userland bug.
try w.print("{s}", .{e.message});
_ = self; // rest is omitted
}
};
I've just refactored my Error's message field, changing its type from []const str to PossiblyStaticStr.
// src/Error.zig
message: PossiblyStaticStr,
// NOTE: unrelated fields, functions, and structs are omitted
pub const PossiblyStaticStr = struct {
static: bool = true,
str: string,
};
When I run zig build check (basically just zig build install but artifacts aren't installed), I get this error:
check
└─ zig build-exe <project-name> Debug native 1 errors
/opt/homebrew/Cellar/zig/0.13.0/lib/zig/std/fmt.zig:471:5: error: invalid format string 's' for type 'Error.PossiblyStaticStr'
@compileError("invalid format string '" ++ fmt ++ "' for type '" ++ @typeName(@TypeOf(value)) ++ "'");
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
referenced by:
formatType__anon_9105: /opt/homebrew/Cellar/zig/0.13.0/lib/zig/std/fmt.zig:578:53
format__anon_5787: /opt/homebrew/Cellar/zig/0.13.0/lib/zig/std/fmt.zig:185:23
print__anon_4037: /opt/homebrew/Cellar/zig/0.13.0/lib/zig/std/io/Writer.zig:24:26
print: /opt/homebrew/Cellar/zig/0.13.0/lib/zig/std/io.zig:324:47
dumpSegfaultInfoPosix: /opt/homebrew/Cellar/zig/0.13.0/lib/zig/std/debug.zig:2643:32
handleSegfaultPosix: /opt/homebrew/Cellar/zig/0.13.0/lib/zig/std/debug.zig:2617:13
attachSegfaultHandler: /opt/homebrew/Cellar/zig/0.13.0/lib/zig/std/debug.zig:2558:36
maybeEnableSegfaultHandler: /opt/homebrew/Cellar/zig/0.13.0/lib/zig/std/debug.zig:2535:18
callMainWithArgs: /opt/homebrew/Cellar/zig/0.13.0/lib/zig/std/start.zig:479:14
main: /opt/homebrew/Cellar/zig/0.13.0/lib/zig/std/start.zig:497:12
error: the following command failed with 1 compilation errors:
/opt/homebrew/Cellar/zig/0.13.0/bin/zig build-exe -freference-trace=256 -ODebug --dep util --dep smart-pointers -Mroot=<omitted>/<project-name>/src/main.zig -ODebug -Mutil=<omitted>/<project-name>/src/util.zig -ODebug -Msmart-pointers=<omitted>/.cache/zig/p/1220d71e011c53ca52d972f5b085339f113e471ba4e4922d9ecc5c10f7b5cc998f19/src/root.zig -fno-emit-bin --cache-dir <omitted>/<project-name>/.zig-cache --global-cache-dir <omitted>/.cache/zig --name <project-name> --listen=-
Expected Output
- I should see an error telling me I'm passing a struct to a
{s} in a format string
The stack trace should include frames within my source code. The offending line (in my code, not in the zig std library) should be more prominent to bring my attention to the bug I introduced. EDIT: fixed in master branch
Zig Version
0.13.0
Steps to Reproduce and Observed Output
I'm writing a graphical formatter that pretty-prints custom
Errorobjects. Note thatErroris a struct, not an error union. Be advised, allNOTEcomments have been added to this issue but do not exist in my code. They exist solely as clarification.I've just refactored my
Error'smessagefield, changing its type from[]const strtoPossiblyStaticStr.When I run
zig build check(basically justzig build installbut artifacts aren't installed), I get this error:Expected Output
{s}in a format stringThe stack trace should include frames within my source code. The offending line (in my code, not in the zig std library) should be more prominent to bring my attention to the bug I introduced.EDIT: fixed in master branch