Commit 3fa0bed985

Andrew Kelley <superjoe30@gmail.com>
2018-04-30 00:22:24
zig fmt: array literal with 1 item on 1 line
1 parent 9543c0a
Changed files (1)
std
std/zig/parser.zig
@@ -3730,6 +3730,16 @@ pub const Parser = struct {
                                     try stack.append(RenderState { .Expression = suffix_op.lhs });
                                     continue;
                                 }
+                                if (exprs.len == 1) {
+                                    const expr = exprs.at(0);
+
+                                    try stack.append(RenderState { .Text = "}" });
+                                    try stack.append(RenderState { .Expression = expr });
+                                    try stack.append(RenderState { .Text = " {" });
+                                    try stack.append(RenderState { .Expression = suffix_op.lhs });
+                                    continue;
+                                }
+
                                 try stack.append(RenderState { .Text = "}"});
                                 try stack.append(RenderState.PrintIndent);
                                 try stack.append(RenderState { .Indent = indent });
@@ -4513,6 +4523,13 @@ fn testCanonical(source: []const u8) !void {
     }
 }
 
+test "zig fmt: array literal with 1 item on 1 line" {
+    try testCanonical(
+        \\var s = []const u64 {0} ** 25;
+        \\
+    );
+}
+
 test "zig fmt: preserve same-line comment after a statement" {
     try testCanonical(
         \\test "" {