aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Kelley <superjoe30@gmail.com>2018-04-29 18:22:24 -0400
committerAndrew Kelley <superjoe30@gmail.com>2018-04-29 18:22:39 -0400
commit3fa0bed985b8de950859d4c482efe9cb30fdaf27 (patch)
tree290017fef7a955b7e9a5ab2ea38abf650023a0ed
parent9543c0a7cc0bbdccc405370e224b546c56b76a0f (diff)
downloadzig-3fa0bed985b8de950859d4c482efe9cb30fdaf27.tar.gz
zig-3fa0bed985b8de950859d4c482efe9cb30fdaf27.zip
zig fmt: array literal with 1 item on 1 line
-rw-r--r--std/zig/parser.zig17
1 files changed, 17 insertions, 0 deletions
diff --git a/std/zig/parser.zig b/std/zig/parser.zig
index cfc880ff11..6a6bd49f6e 100644
--- a/std/zig/parser.zig
+++ b/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 "" {