| ... | @@ -228,7 +228,7 @@ pub fn formatValue(value: var, context: var, output: fn(@typeOf(context), []cons | ... | @@ -228,7 +228,7 @@ pub fn formatValue(value: var, context: var, output: fn(@typeOf(context), []cons |
| 228 | if (@typeId(T.Child) == builtin.TypeId.Array and T.Child.Child == u8) { | 228 | if (@typeId(T.Child) == builtin.TypeId.Array and T.Child.Child == u8) { |
| 229 | return output(context, (*value)[0..]); | 229 | return output(context, (*value)[0..]); |
| 230 | } else { | 230 | } else { |
| 231 | @compileError("Unable to format type '" ++ @typeName(T) ++ "'"); | 231 | return format(context, output, "{}@{x}", @typeName(T.Child), @ptrToInt(value)); |
| 232 | } | 232 | } |
| 233 | }, | 233 | }, |
| 234 | else => if (@canImplicitCast([]const u8, value)) { | 234 | else => if (@canImplicitCast([]const u8, value)) { |
| ... | @@ -546,6 +546,12 @@ test "parse unsigned comptime" { | ... | @@ -546,6 +546,12 @@ test "parse unsigned comptime" { |
| 546 | } | 546 | } |
| 547 | } | 547 | } |
| 548 | | 548 | |
| | 549 | // Dummy field because of https://github.com/zig-lang/zig/issues/557. |
| | 550 | // At top level because of https://github.com/zig-lang/zig/issues/675. |
| | 551 | const Struct = struct { |
| | 552 | unused: u8, |
| | 553 | }; |
| | 554 | |
| 549 | test "fmt.format" { | 555 | test "fmt.format" { |
| 550 | { | 556 | { |
| 551 | var buf1: [32]u8 = undefined; | 557 | var buf1: [32]u8 = undefined; |
| ... | @@ -577,6 +583,14 @@ test "fmt.format" { | ... | @@ -577,6 +583,14 @@ test "fmt.format" { |
| 577 | const result = try bufPrint(buf1[0..], "u3: {}\n", value); | 583 | const result = try bufPrint(buf1[0..], "u3: {}\n", value); |
| 578 | assert(mem.eql(u8, result, "u3: 5\n")); | 584 | assert(mem.eql(u8, result, "u3: 5\n")); |
| 579 | } | 585 | } |
| | 586 | { |
| | 587 | var buf1: [32]u8 = undefined; |
| | 588 | const value = Struct { |
| | 589 | .unused = 42, |
| | 590 | }; |
| | 591 | const result = try bufPrint(buf1[0..], "pointer: {}\n", &value); |
| | 592 | assert(mem.startsWith(u8, result, "pointer: Struct@")); |
| | 593 | } |
| 580 | | 594 | |
| 581 | // TODO get these tests passing in release modes | 595 | // TODO get these tests passing in release modes |
| 582 | // https://github.com/zig-lang/zig/issues/564 | 596 | // https://github.com/zig-lang/zig/issues/564 |