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(
327327 max_depth: usize,
328328) @TypeOf(writer).Error!void {
329329 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))));
331331 try writer.writeAll("@");
332332 try formatInt(@ptrToInt(value), 16, false, FormatOptions{}, writer);
333333 return;
......@@ -1246,6 +1246,10 @@ test "optional" {
12461246 const value: ?i32 = null;
12471247 try testFmt("optional: null\n", "optional: {}\n", .{value});
12481248 }
1249 {
1250 const value = @intToPtr(?*i32, 0xf000d000);
1251 try testFmt("optional: *i32@f000d000\n", "optional: {*}\n", .{value});
1252 }
12491253}
12501254
12511255test "error" {