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 {...@@ -1673,6 +1673,10 @@ pub const Node = struct {
1673 }1673 }
16741674
1675 pub fn firstToken(self: &SuffixOp) TokenIndex {1675 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 }
1676 return self.lhs.firstToken();1680 return self.lhs.firstToken();
1677 }1681 }
16781682
std/zig/parser_test.zig+11
...@@ -1,3 +1,14 @@...@@ -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
1test "zig fmt: 2nd arg multiline string" {12test "zig fmt: 2nd arg multiline string" {
2 try testCanonical(13 try testCanonical(
3 \\comptime {14 \\comptime {
std/zig/render.zig+5-5
...@@ -213,13 +213,13 @@ fn renderExpression(allocator: &mem.Allocator, stream: var, tree: &ast.Tree, ind...@@ -213,13 +213,13 @@ fn renderExpression(allocator: &mem.Allocator, stream: var, tree: &ast.Tree, ind
213 const async_attr = @fieldParentPtr(ast.Node.AsyncAttribute, "base", base);213 const async_attr = @fieldParentPtr(ast.Node.AsyncAttribute, "base", base);
214214
215 if (async_attr.allocator_type) |allocator_type| {215 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);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);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);220 return renderToken(tree, stream, tree.nextToken(allocator_type.lastToken()), indent, start_col, space); // >
221 } else {221 } 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
223 }223 }
224 },224 },
225225