authorgravatar for thatlemon@gmail.comLemonBoy <thatlemon@gmail.com> 2020-09-16 13:45:54+02:00
committergravatar for thatlemon@gmail.comLemonBoy <thatlemon@gmail.com> 2020-09-16 13:45:54+02:00
logbb9a4ad6e903ad2f9c137bca56bdf2dd6fc65d03
tree999547058a55d513a3bb5e88c41dd8b029d77f6b
parent281fc10ec5aa8052490b9f951e0ceed1b7008ff4

std: Fix {*} printing of non-pointer types

Fixes a regression introduced in #6246. Adds a test to make sure this won't happen again.

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

lib/std/fmt.zig+5-1
...@@ -327,7 +327,7 @@ pub fn formatType(...@@ -327,7 +327,7 @@ pub fn formatType(
327 max_depth: usize,327 max_depth: usize,
328) @TypeOf(writer).Error!void {328) @TypeOf(writer).Error!void {
329 if (comptime std.mem.eql(u8, fmt, "*")) {329 if (comptime std.mem.eql(u8, fmt, "*")) {
330 try writer.writeAll(@typeName(@typeInfo(@TypeOf(value)).Pointer.child));330 try writer.writeAll(@typeName(std.meta.Child(@TypeOf(value))));
331 try writer.writeAll("@");331 try writer.writeAll("@");
332 try formatInt(@ptrToInt(value), 16, false, FormatOptions{}, writer);332 try formatInt(@ptrToInt(value), 16, false, FormatOptions{}, writer);
333 return;333 return;
...@@ -1246,6 +1246,10 @@ test "optional" {...@@ -1246,6 +1246,10 @@ test "optional" {
1246 const value: ?i32 = null;1246 const value: ?i32 = null;
1247 try testFmt("optional: null\n", "optional: {}\n", .{value});1247 try testFmt("optional: null\n", "optional: {}\n", .{value});
1248 }1248 }
1249 {
1250 const value = @intToPtr(?*i32, 0xf000d000);
1251 try testFmt("optional: *i32@f000d000\n", "optional: {*}\n", .{value});
1252 }
1249}1253}
12501254
1251test "error" {1255test "error" {