Commit a7670e80a4

Jimmi Holst Christensen <jimmi@ziglang.org>
2018-12-19 16:07:35
Added formatting of function pointers (#1843)
1 parent 45e72c0
Changed files (1)
std
std/fmt/index.zig
@@ -243,6 +243,9 @@ pub fn formatType(
             }
             return format(context, Errors, output, "{}@{x}", @typeName(T.Child), @ptrToInt(&value));
         },
+        builtin.TypeId.Fn => {
+            return format(context, Errors, output, "{}@{x}", @typeName(T), @ptrToInt(value));
+        },
         else => @compileError("Unable to format type '" ++ @typeName(T) ++ "'"),
     }
 }
@@ -1013,6 +1016,10 @@ test "fmt.format" {
         const value = @intToPtr(fn () void, 0xdeadbeef);
         try testFmt("pointer: fn() void@deadbeef\n", "pointer: {}\n", value);
     }
+    {
+        const value = @intToPtr(fn () void, 0xdeadbeef);
+        try testFmt("pointer: fn() void@deadbeef\n", "pointer: {}\n", value);
+    }
     try testFmt("buf: Test \n", "buf: {s5}\n", "Test");
     try testFmt("buf: Test\n Other text", "buf: {s}\n Other text", "Test");
     try testFmt("cstr: Test C\n", "cstr: {s}\n", c"Test C");