Skip to content

Attempting to format with width on enum gives assert error #25795

@Philogy

Description

@Philogy

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    error messageThis issue points out an error message that is unhelpful and should be improved.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions