Commit d645500883

Shritesh Bhattarai <shritesh@shritesh.com>
2019-04-01 04:28:28
fmt: fix first line comment indent in struct init
1 parent 0563e8e
Changed files (2)
std/zig/parser_test.zig
@@ -1027,6 +1027,19 @@ test "zig fmt: line comments in struct initializer" {
     );
 }
 
+test "zig fmt: first line comment in struct initializer" {
+    try testCanonical(
+        \\pub async fn acquire(self: *Self) HeldLock {
+        \\    return HeldLock{
+        \\        // TODO guaranteed allocation elision
+        \\        .held = await (async self.lock.acquire() catch unreachable),
+        \\        .value = &self.private_data,
+        \\    };
+        \\}
+        \\
+    );
+}
+
 test "zig fmt: doc comments before struct field" {
     try testCanonical(
         \\pub const Allocator = struct {
std/zig/render.zig
@@ -658,11 +658,11 @@ fn renderExpression(
                         return renderToken(tree, stream, suffix_op.rtoken, indent, start_col, space);
                     }
 
-                    try renderExpression(allocator, stream, tree, indent, start_col, suffix_op.lhs, Space.None);
-                    try renderToken(tree, stream, lbrace, indent, start_col, Space.Newline);
-
                     const new_indent = indent + indent_delta;
 
+                    try renderExpression(allocator, stream, tree, new_indent, start_col, suffix_op.lhs, Space.None);
+                    try renderToken(tree, stream, lbrace, new_indent, start_col, Space.Newline);
+
                     var it = field_inits.iterator(0);
                     while (it.next()) |field_init| {
                         try stream.writeByteNTimes(' ', new_indent);