zig icon indicating copy to clipboard operation
zig copied to clipboard

Attempting to format with width on enum gives assert error

Open Philogy opened this issue 1 month ago • 1 comments

Zig Version

0.15.1

Steps to Reproduce and Observed Output

Minimal Repro

    const my_enum = enum { variant };
    const value: my_enum = .variant;
    std.debug.print("value: {:12}\n", .{value});

Output Error

value: thread 5367751 panic: reached unreachable code
/opt/homebrew/Cellar/zig/0.15.1/lib/zig/std/debug.zig:559:14: 0x104babe07 in assert (zenzei)
    if (!ok) unreachable; // assertion failure
             ^
/opt/homebrew/Cellar/zig/0.15.1/lib/zig/std/Io/Writer.zig:1402:11: 0x104c0b94f in optionsForbidden (zenzei)
    assert(options.width == null);
          ^
/opt/homebrew/Cellar/zig/0.15.1/lib/zig/std/Io/Writer.zig:1252:29: 0x104c4d513 in printValue__anon_21994 (zenzei)
            optionsForbidden(options);
                            ^
/opt/homebrew/Cellar/zig/0.15.1/lib/zig/std/Io/Writer.zig:700:25: 0x104c43cc7 in print__anon_19725 (zenzei)
        try w.printValue(
                        ^
/opt/homebrew/Cellar/zig/0.15.1/lib/zig/std/debug.zig:231:23: 0x104c4049f in print__anon_19477 (zenzei)
    nosuspend bw.print(fmt, args) catch return;
                      ^
/Users/philogy/Documents/Sensei/zenzei/src/main.zig:12:20: 0x104c4041f in main (zenzei)
    std.debug.print("value: {:12}\n", .{value});

Expected Output

Ideally a simple print with alignment:

value:     .variant

Or at least a better panic message in the shape of:

thread 5364281 panic: formatting with width, alignment & fill not supported for enums
     .... remaining trace

Philogy avatar Nov 03 '25 11:11 Philogy

New to zig, so not sure if this is an intended limitation, seems a bit arbitrary though? Could be a good first issue I'd be happy to try my hands at

Philogy avatar Nov 03 '25 11:11 Philogy