commit bb9a4ad6e903ad2f9c137bca56bdf2dd6fc65d03 (tree)
parent 281fc10ec5aa8052490b9f951e0ceed1b7008ff4
Author: LemonBoy <thatlemon@gmail.com>
Date: Wed, 16 Sep 2020 13:45:54 +0200
std: Fix {*} printing of non-pointer types
Fixes a regression introduced in #6246.
Adds a test to make sure this won't happen again.
Diffstat:
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/lib/std/fmt.zig b/lib/std/fmt.zig
@@ -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" {