Skip to content

Commit cdf30c3

Browse files
committed
zig fmt: fix implementation of firstToken() for fn call
1 parent cd325e4 commit cdf30c3

File tree

3 files changed

+20
-5
lines changed

3 files changed

+20
-5
lines changed

std/zig/ast.zig

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
test "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+
112
test "zig fmt: 2nd arg multiline string" {
213
try testCanonical(
314
\\comptime {

std/zig/render.zig

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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

0 commit comments

Comments
 (0)