Skip to content

Conversation

@snoire
Copy link
Contributor

@snoire snoire commented Oct 27, 2025

The {t} format specifier in Writer.print prints the tag name for enums and errors. However, it did not support enum literals, which caused an invalidFmtError when an enum literal was passed to it.

This simple change adds .enum_literal to the type check, allowing enum literals to be printed using their tag name, which makes the behavior consistent with other enum types.

@squeek502
Copy link
Member

squeek502 commented Nov 6, 2025

Mind adding

    try expectFmt("hello_world", "{t}", .{.hello_world});

to

zig/lib/std/fmt.zig

Lines 1250 to 1252 in 416bf1d

test "enum-literal" {
try expectFmt(".hello_world", "{}", .{.hello_world});
}

?

@snoire snoire force-pushed the enum-literal-format-support branch from d8c4f7d to b4b54b5 Compare November 6, 2025 05:45
@snoire
Copy link
Contributor Author

snoire commented Nov 6, 2025

Thanks for the suggestion! I've added the test case.

@squeek502 squeek502 enabled auto-merge November 6, 2025 06:48
@squeek502 squeek502 merged commit 4937aef into ziglang:master Nov 6, 2025
17 of 18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants