fmt: Fix one more edge case in container formatting

This commit is contained in:
LemonBoy 2020-02-03 15:24:07 +01:00 committed by Andrew Kelley
parent 5504f155aa
commit 1658becb62
2 changed files with 12 additions and 0 deletions

View File

@ -7,6 +7,16 @@ test "zig fmt: trailing comma in container declaration" {
\\const X = struct { foo: i32 align(4) = 1, bar: i32 align(4) = 2 };
\\
);
try testCanonical(
\\test "" {
\\ comptime {
\\ const X = struct {
\\ x: i32
\\ };
\\ }
\\}
\\
);
try testTransform(
\\const X = struct {
\\ foo: i32, bar: i8 };

View File

@ -1224,6 +1224,8 @@ fn renderExpression(
const space_after_decl: Space = if (it.peek() == null) .Newline else .Space;
try renderContainerDecl(allocator, stream, tree, new_indent, start_col, decl.*, space_after_decl);
}
try stream.writeByteNTimes(' ', indent);
} else {
// All the declarations on the same line
try renderToken(tree, stream, container_decl.lbrace_token, indent, start_col, .Space); // {