| ... | @@ -504,7 +504,6 @@ pub fn Serializer(Writer: type) type { | ... | @@ -504,7 +504,6 @@ pub fn Serializer(Writer: type) type { |
| 504 | .bool, .null => try std.fmt.format(self.writer, "{}", .{val}), | 504 | .bool, .null => try std.fmt.format(self.writer, "{}", .{val}), |
| 505 | .enum_literal => try self.ident(@tagName(val)), | 505 | .enum_literal => try self.ident(@tagName(val)), |
| 506 | .@"enum" => try self.ident(@tagName(val)), | 506 | .@"enum" => try self.ident(@tagName(val)), |
| 507 | .void => try self.writer.writeAll("{}"), | | |
| 508 | .pointer => |pointer| { | 507 | .pointer => |pointer| { |
| 509 | // Try to serialize as a string | 508 | // Try to serialize as a string |
| 510 | const item: ?type = switch (@typeInfo(pointer.child)) { | 509 | const item: ?type = switch (@typeInfo(pointer.child)) { |
| ... | @@ -579,15 +578,21 @@ pub fn Serializer(Writer: type) type { | ... | @@ -579,15 +578,21 @@ pub fn Serializer(Writer: type) type { |
| 579 | }, | 578 | }, |
| 580 | .@"union" => |@"union"| { | 579 | .@"union" => |@"union"| { |
| 581 | comptime assert(@"union".tag_type != null); | 580 | comptime assert(@"union".tag_type != null); |
| 582 | var container = try self.startStruct(.{ .whitespace_style = .{ .fields = 1 } }); | | |
| 583 | switch (val) { | 581 | switch (val) { |
| 584 | inline else => |pl, tag| try container.fieldArbitraryDepth( | 582 | inline else => |pl, tag| if (@TypeOf(pl) == void) |
| 585 | @tagName(tag), | 583 | try self.writer.print(".{s}", .{@tagName(tag)}) |
| 586 | pl, | 584 | else { |
| 587 | options, | 585 | var container = try self.startStruct(.{ .whitespace_style = .{ .fields = 1 } }); |
| 588 | ), | 586 | |
| | 587 | try container.fieldArbitraryDepth( |
| | 588 | @tagName(tag), |
| | 589 | pl, |
| | 590 | options, |
| | 591 | ); |
| | 592 | |
| | 593 | try container.finish(); |
| | 594 | }, |
| 589 | } | 595 | } |
| 590 | try container.finish(); | | |
| 591 | }, | 596 | }, |
| 592 | .optional => if (val) |inner| { | 597 | .optional => if (val) |inner| { |
| 593 | try self.valueArbitraryDepth(inner, options); | 598 | try self.valueArbitraryDepth(inner, options); |
| ... | @@ -1116,6 +1121,12 @@ test "std.zon stringify whitespace, high level API" { | ... | @@ -1116,6 +1121,12 @@ test "std.zon stringify whitespace, high level API" { |
| 1116 | \\ 3, | 1121 | \\ 3, |
| 1117 | \\} } | 1122 | \\} } |
| 1118 | , .{ .inner = .{ 1, 2, 3 } }, .{}); | 1123 | , .{ .inner = .{ 1, 2, 3 } }, .{}); |
| | 1124 | |
| | 1125 | const UnionWithVoid = union(enum) { a, b: void, c: u8 }; |
| | 1126 | |
| | 1127 | try expectSerializeEqual( |
| | 1128 | \\.a |
| | 1129 | , UnionWithVoid.a, .{}); |
| 1119 | } | 1130 | } |
| 1120 | | 1131 | |
| 1121 | test "std.zon stringify whitespace, low level API" { | 1132 | test "std.zon stringify whitespace, low level API" { |