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

Fixes a regression introduced in #6246.
Adds a test to make sure this won't happen again.
This commit is contained in:
LemonBoy 2020-09-16 13:45:54 +02:00
parent 281fc10ec5
commit bb9a4ad6e9

View File

@ -327,7 +327,7 @@ pub fn formatType(
max_depth: usize,
) @TypeOf(writer).Error!void {
if (comptime std.mem.eql(u8, fmt, "*")) {
try writer.writeAll(@typeName(@typeInfo(@TypeOf(value)).Pointer.child));
try writer.writeAll(@typeName(std.meta.Child(@TypeOf(value))));
try writer.writeAll("@");
try formatInt(@ptrToInt(value), 16, false, FormatOptions{}, writer);
return;
@ -1246,6 +1246,10 @@ test "optional" {
const value: ?i32 = null;
try testFmt("optional: null\n", "optional: {}\n", .{value});
}
{
const value = @intToPtr(?*i32, 0xf000d000);
try testFmt("optional: *i32@f000d000\n", "optional: {*}\n", .{value});
}
}
test "error" {