Skip to content

Commit a7670e8

Browse files
Hejsilandrewrk
authored andcommitted
Added formatting of function pointers (#1843)
1 parent 45e72c0 commit a7670e8

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

std/fmt/index.zig

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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");

0 commit comments

Comments
 (0)