| ... | @@ -723,7 +723,9 @@ fn formatIntUnsigned( | ... | @@ -723,7 +723,9 @@ fn formatIntUnsigned( |
| 723 | // max_int_digits accounts for the minus sign. when printing an unsigned | 723 | // max_int_digits accounts for the minus sign. when printing an unsigned |
| 724 | // number we don't need to do that. | 724 | // number we don't need to do that. |
| 725 | var buf: [max_int_digits - 1]u8 = undefined; | 725 | var buf: [max_int_digits - 1]u8 = undefined; |
| 726 | var a = if (@sizeOf(@typeOf(value)) == 1) u8(value) else value; | 726 | const min_int_bits = comptime math.max(@typeOf(value).bit_count, @typeOf(base).bit_count); |
| | 727 | const MinInt = @IntType(@typeOf(value).is_signed, min_int_bits); |
| | 728 | var a: MinInt = value; |
| 727 | var index: usize = buf.len; | 729 | var index: usize = buf.len; |
| 728 | | 730 | |
| 729 | while (true) { | 731 | while (true) { |
| ... | @@ -965,6 +967,14 @@ test "fmt.format" { | ... | @@ -965,6 +967,14 @@ test "fmt.format" { |
| 965 | try testFmt("struct: Struct{ .field = 42 }\n", "struct: {}\n", value); | 967 | try testFmt("struct: Struct{ .field = 42 }\n", "struct: {}\n", value); |
| 966 | try testFmt("struct: Struct{ .field = 42 }\n", "struct: {}\n", &value); | 968 | try testFmt("struct: Struct{ .field = 42 }\n", "struct: {}\n", &value); |
| 967 | } | 969 | } |
| | 970 | { |
| | 971 | const Struct = struct { |
| | 972 | a: u0, |
| | 973 | b: u1, |
| | 974 | }; |
| | 975 | const value = Struct{ .a = 0, .b = 1 }; |
| | 976 | try testFmt("struct: Struct{ .a = 0, .b = 1 }\n", "struct: {}\n", value); |
| | 977 | } |
| 968 | { | 978 | { |
| 969 | const Enum = enum { | 979 | const Enum = enum { |
| 970 | One, | 980 | One, |