authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-05-29 03:47:27-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-05-29 03:47:27-04:00
logcdf30c31ea36365859dd81c207aede3c45c4e022
tree73410095aa83f31d6c329acd8debdb0b48c31400
parentcd325e408e2d23734ba84e412b6f1706cf442434

zig fmt: fix implementation of firstToken() for fn call


3 files changed, 20 insertions(+), 5 deletions(-)

std/zig/ast.zig+4
......@@ -1673,6 +1673,10 @@ pub const Node = struct {
16731673 }
16741674
16751675 pub fn firstToken(self: &SuffixOp) TokenIndex {
1676 switch (self.op) {
1677 @TagType(Op).Call => |*call_info| if (call_info.async_attr) |async_attr| return async_attr.firstToken(),
1678 else => {},
1679 }
16761680 return self.lhs.firstToken();
16771681 }
16781682
std/zig/parser_test.zig+11
......@@ -1,3 +1,14 @@
1test "zig fmt: async call in if condition" {
2 try testCanonical(
3 \\comptime {
4 \\ if (async<a> b()) {
5 \\ a();
6 \\ }
7 \\}
8 \\
9 );
10}
11
112test "zig fmt: 2nd arg multiline string" {
213 try testCanonical(
314 \\comptime {
std/zig/render.zig+5-5
......@@ -213,13 +213,13 @@ fn renderExpression(allocator: &mem.Allocator, stream: var, tree: &ast.Tree, ind
213213 const async_attr = @fieldParentPtr(ast.Node.AsyncAttribute, "base", base);
214214
215215 if (async_attr.allocator_type) |allocator_type| {
216 try renderToken(tree, stream, async_attr.async_token, indent, start_col, Space.None);
216 try renderToken(tree, stream, async_attr.async_token, indent, start_col, Space.None); // async
217217
218 try renderToken(tree, stream, tree.nextToken(async_attr.async_token), indent, start_col, Space.None);
219 try renderExpression(allocator, stream, tree, indent, start_col, allocator_type, Space.None);
220 return renderToken(tree, stream, tree.nextToken(allocator_type.lastToken()), indent, start_col, space);
218 try renderToken(tree, stream, tree.nextToken(async_attr.async_token), indent, start_col, Space.None); // <
219 try renderExpression(allocator, stream, tree, indent, start_col, allocator_type, Space.None); // allocator
220 return renderToken(tree, stream, tree.nextToken(allocator_type.lastToken()), indent, start_col, space); // >
221221 } else {
222 return renderToken(tree, stream, async_attr.async_token, indent, start_col, space);
222 return renderToken(tree, stream, async_attr.async_token, indent, start_col, space); // async
223223 }
224224 },
225225