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(...@@ -243,6 +243,9 @@ pub fn formatType(
243 }243 }
244 return format(context, Errors, output, "{}@{x}", @typeName(T.Child), @ptrToInt(&value));244 return format(context, Errors, output, "{}@{x}", @typeName(T.Child), @ptrToInt(&value));
245 },245 },
246 builtin.TypeId.Fn => {
247 return format(context, Errors, output, "{}@{x}", @typeName(T), @ptrToInt(value));
248 },
246 else => @compileError("Unable to format type '" ++ @typeName(T) ++ "'"),249 else => @compileError("Unable to format type '" ++ @typeName(T) ++ "'"),
247 }250 }
248}251}
...@@ -1013,6 +1016,10 @@ test "fmt.format" {...@@ -1013,6 +1016,10 @@ test "fmt.format" {
1013 const value = @intToPtr(fn () void, 0xdeadbeef);1016 const value = @intToPtr(fn () void, 0xdeadbeef);
1014 try testFmt("pointer: fn() void@deadbeef\n", "pointer: {}\n", value);1017 try testFmt("pointer: fn() void@deadbeef\n", "pointer: {}\n", value);
1015 }1018 }
1019 {
1020 const value = @intToPtr(fn () void, 0xdeadbeef);
1021 try testFmt("pointer: fn() void@deadbeef\n", "pointer: {}\n", value);
1022 }
1016 try testFmt("buf: Test \n", "buf: {s5}\n", "Test");1023 try testFmt("buf: Test \n", "buf: {s5}\n", "Test");
1017 try testFmt("buf: Test\n Other text", "buf: {s}\n Other text", "Test");1024 try testFmt("buf: Test\n Other text", "buf: {s}\n Other text", "Test");
1018 try testFmt("cstr: Test C\n", "cstr: {s}\n", c"Test C");1025 try testFmt("cstr: Test C\n", "cstr: {s}\n", c"Test C");