zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit a471a57560401c5562c4dc3e588227b689bf9487 (tree)
parent 343249efd845c30fbdcb18a37ebb356ab19da742
Author: LemonBoy <thatlemon@gmail.com>
Date:   Sun, 13 Dec 2020 20:02:15 +0100

std: Fix formatting of type values

Closes #7429

Diffstat:
Mlib/std/fmt.zig | 8+++++++-
1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/lib/std/fmt.zig b/lib/std/fmt.zig @@ -537,7 +537,7 @@ pub fn formatType( .Fn => { return format(writer, "{}@{x}", .{ @typeName(T), @ptrToInt(value) }); }, - .Type => return writer.writeAll(@typeName(T)), + .Type => return formatBuf(@typeName(value), options, writer), .EnumLiteral => { const buffer = [_]u8{'.'} ++ @tagName(value); return formatType(buffer, fmt, options, writer, max_depth); @@ -2052,6 +2052,12 @@ test "null" { try testFmt("null", "{}", .{inst}); } +test "type" { + try testFmt("u8", "{}", .{u8}); + try testFmt("?f32", "{}", .{?f32}); + try testFmt("[]const u8", "{}", .{[]const u8}); +} + test "named arguments" { try testFmt("hello world!", "{} world{c}", .{ "hello", '!' }); try testFmt("hello world!", "{[greeting]} world{[punctuation]c}", .{ .punctuation = '!', .greeting = "hello" });