authorgravatar for jhc@dismail.deJimmi Holst Christensen <jhc@dismail.de> 2018-12-19 16:07:35+01:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-12-19 10:07:35-05:00
loga7670e80a49021fb96d1f9a1bbcbcfc6c1e835ab
tree1417f949edd37999f7f18286dd5e3075172645a3
parent45e72c0b3944b2fa6d06c7018e9648b4ae60006a

Added formatting of function pointers (#1843)


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

std/fmt/index.zig+7
......@@ -243,6 +243,9 @@ pub fn formatType(
243243 }
244244 return format(context, Errors, output, "{}@{x}", @typeName(T.Child), @ptrToInt(&value));
245245 },
246 builtin.TypeId.Fn => {
247 return format(context, Errors, output, "{}@{x}", @typeName(T), @ptrToInt(value));
248 },
246249 else => @compileError("Unable to format type '" ++ @typeName(T) ++ "'"),
247250 }
248251}
......@@ -1013,6 +1016,10 @@ test "fmt.format" {
10131016 const value = @intToPtr(fn () void, 0xdeadbeef);
10141017 try testFmt("pointer: fn() void@deadbeef\n", "pointer: {}\n", value);
10151018 }
1019 {
1020 const value = @intToPtr(fn () void, 0xdeadbeef);
1021 try testFmt("pointer: fn() void@deadbeef\n", "pointer: {}\n", value);
1022 }
10161023 try testFmt("buf: Test \n", "buf: {s5}\n", "Test");
10171024 try testFmt("buf: Test\n Other text", "buf: {s}\n Other text", "Test");
10181025 try testFmt("cstr: Test C\n", "cstr: {s}\n", c"Test C");