mirror of
https://github.com/ziglang/zig.git
synced 2026-02-06 14:37:04 +00:00
zig fmt: fix implementation of firstToken() for fn call
This commit is contained in:
parent
cd325e408e
commit
cdf30c31ea
@ -1673,6 +1673,10 @@ pub const Node = struct {
|
||||
}
|
||||
|
||||
pub fn firstToken(self: &SuffixOp) TokenIndex {
|
||||
switch (self.op) {
|
||||
@TagType(Op).Call => |*call_info| if (call_info.async_attr) |async_attr| return async_attr.firstToken(),
|
||||
else => {},
|
||||
}
|
||||
return self.lhs.firstToken();
|
||||
}
|
||||
|
||||
|
||||
@ -1,3 +1,14 @@
|
||||
test "zig fmt: async call in if condition" {
|
||||
try testCanonical(
|
||||
\\comptime {
|
||||
\\ if (async<a> b()) {
|
||||
\\ a();
|
||||
\\ }
|
||||
\\}
|
||||
\\
|
||||
);
|
||||
}
|
||||
|
||||
test "zig fmt: 2nd arg multiline string" {
|
||||
try testCanonical(
|
||||
\\comptime {
|
||||
|
||||
@ -213,13 +213,13 @@ fn renderExpression(allocator: &mem.Allocator, stream: var, tree: &ast.Tree, ind
|
||||
const async_attr = @fieldParentPtr(ast.Node.AsyncAttribute, "base", base);
|
||||
|
||||
if (async_attr.allocator_type) |allocator_type| {
|
||||
try renderToken(tree, stream, async_attr.async_token, indent, start_col, Space.None);
|
||||
try renderToken(tree, stream, async_attr.async_token, indent, start_col, Space.None); // async
|
||||
|
||||
try renderToken(tree, stream, tree.nextToken(async_attr.async_token), indent, start_col, Space.None);
|
||||
try renderExpression(allocator, stream, tree, indent, start_col, allocator_type, Space.None);
|
||||
return renderToken(tree, stream, tree.nextToken(allocator_type.lastToken()), indent, start_col, space);
|
||||
try renderToken(tree, stream, tree.nextToken(async_attr.async_token), indent, start_col, Space.None); // <
|
||||
try renderExpression(allocator, stream, tree, indent, start_col, allocator_type, Space.None); // allocator
|
||||
return renderToken(tree, stream, tree.nextToken(allocator_type.lastToken()), indent, start_col, space); // >
|
||||
} else {
|
||||
return renderToken(tree, stream, async_attr.async_token, indent, start_col, space);
|
||||
return renderToken(tree, stream, async_attr.async_token, indent, start_col, space); // async
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user