authorgravatar for thatlemon@gmail.comLemonBoy <thatlemon@gmail.com> 2020-12-13 20:02:15+01:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-12-13 23:21:23-05:00
loga471a57560401c5562c4dc3e588227b689bf9487
treed7761cc097c7bd0791ac025392b6a45a27567dee
parent343249efd845c30fbdcb18a37ebb356ab19da742

std: Fix formatting of type values

Closes #7429

1 files changed, 7 insertions(+), 1 deletions(-)

lib/std/fmt.zig+7-1
...@@ -537,7 +537,7 @@ pub fn formatType(...@@ -537,7 +537,7 @@ pub fn formatType(
537 .Fn => {537 .Fn => {
538 return format(writer, "{}@{x}", .{ @typeName(T), @ptrToInt(value) });538 return format(writer, "{}@{x}", .{ @typeName(T), @ptrToInt(value) });
539 },539 },
540 .Type => return writer.writeAll(@typeName(T)),540 .Type => return formatBuf(@typeName(value), options, writer),
541 .EnumLiteral => {541 .EnumLiteral => {
542 const buffer = [_]u8{'.'} ++ @tagName(value);542 const buffer = [_]u8{'.'} ++ @tagName(value);
543 return formatType(buffer, fmt, options, writer, max_depth);543 return formatType(buffer, fmt, options, writer, max_depth);
...@@ -2052,6 +2052,12 @@ test "null" {...@@ -2052,6 +2052,12 @@ test "null" {
2052 try testFmt("null", "{}", .{inst});2052 try testFmt("null", "{}", .{inst});
2053}2053}
20542054
2055test "type" {
2056 try testFmt("u8", "{}", .{u8});
2057 try testFmt("?f32", "{}", .{?f32});
2058 try testFmt("[]const u8", "{}", .{[]const u8});
2059}
2060
2055test "named arguments" {2061test "named arguments" {
2056 try testFmt("hello world!", "{} world{c}", .{ "hello", '!' });2062 try testFmt("hello world!", "{} world{c}", .{ "hello", '!' });
2057 try testFmt("hello world!", "{[greeting]} world{[punctuation]c}", .{ .punctuation = '!', .greeting = "hello" });2063 try testFmt("hello world!", "{[greeting]} world{[punctuation]c}", .{ .punctuation = '!', .greeting = "hello" });