| ... | ... | @@ -166,6 +166,11 @@ pub fn formatType( |
| 166 | 166 | |
| 167 | 167 | if (has_cust_fmt) return value.format(fmt, context, Errors, output); |
| 168 | 168 | try output(context, @typeName(T)); |
| 169 | if (comptime @typeId(T) == builtin.TypeId.Enum) { |
| 170 | try output(context, "."); |
| 171 | try formatType(@tagName(value), "", context, Errors, output); |
| 172 | return; |
| 173 | } |
| 169 | 174 | comptime var field_i = 0; |
| 170 | 175 | inline while (field_i < @memberCount(T)) : (field_i += 1) { |
| 171 | 176 | if (field_i == 0) { |
| ... | ... | @@ -934,6 +939,15 @@ test "fmt.format" { |
| 934 | 939 | try testFmt("struct: Struct{ .field = 42 }\n", "struct: {}\n", value); |
| 935 | 940 | try testFmt("struct: Struct{ .field = 42 }\n", "struct: {}\n", &value); |
| 936 | 941 | } |
| 942 | { |
| 943 | const Enum = enum { |
| 944 | One, |
| 945 | Two, |
| 946 | }; |
| 947 | const value = Enum.Two; |
| 948 | try testFmt("enum: Enum.Two\n", "enum: {}\n", value); |
| 949 | try testFmt("enum: Enum.Two\n", "enum: {}\n", &value); |
| 950 | } |
| 937 | 951 | { |
| 938 | 952 | var buf1: [32]u8 = undefined; |
| 939 | 953 | const value: f32 = 1.34; |