authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-05-30 21:53:38 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-05-30 21:53:38 -07:00
loge96a016e3fe9b942e66d24dc95e484323767f357
tree9085d19f360689e43a3d7b35027171c8fd0268e4
parent5db3ab392d43e25bc7fc0243fd7b131399cae7c8
signaturebadge-check Signed by SSH key SHA256:4hHJbtBRU58AYXwjL7fkz2fnQHdiye8x1QpTCQ0sHNw

fmt: this enum behavior was super footgun-y


1 files changed, 5 insertions(+), 18 deletions(-)

fmt.zig+5-18
...@@ -467,27 +467,14 @@ fn formatType(value: anytype, comptime fmt: []const u8, options: FormatOptions,...@@ -467,27 +467,14 @@ fn formatType(value: anytype, comptime fmt: []const u8, options: FormatOptions,
467 return writer.writeAll(@errorName(value));467 return writer.writeAll(@errorName(value));
468 },468 },
469 .@"enum" => |enumInfo| {469 .@"enum" => |enumInfo| {
470 try writer.writeAll(@typeName(T));470 if (comptime std.mem.eql(u8, actual_fmt, "d")) {
471 if (enumInfo.is_exhaustive) {471 try formatInt(@intFromEnum(value), 10, .lower, options, writer);
472 if (actual_fmt.len != 0) invalidFmtError(fmt, value);
473 try writer.writeAll(".");
474 try writer.writeAll(@tagName(value));
475 return;472 return;
476 }473 }
477474 if (comptime std.mem.eql(u8, actual_fmt, "s") and enumInfo.is_exhaustive) {
478 // Use @tagName only if value is one of known fields475 try writer.writeAll(@tagName(value));
479 @setEvalBranchQuota(3 * enumInfo.fields.len);476 return;
480 inline for (enumInfo.fields) |enumField| {
481 if (@intFromEnum(value) == enumField.value) {
482 try writer.writeAll(".");
483 try writer.writeAll(@tagName(value));
484 return;
485 }
486 }477 }
487
488 try writer.writeAll("(");
489 try formatType(@intFromEnum(value), actual_fmt, options, writer, max_depth);
490 try writer.writeAll(")");
491 },478 },
492 .@"union" => |info| {479 .@"union" => |info| {
493 if (actual_fmt.len != 0) invalidFmtError(fmt, value);480 if (actual_fmt.len != 0) invalidFmtError(fmt, value);