fmt: support trailing comma after var_args
This commit is contained in:
parent
6cc2d3938e
commit
2f236e6efb
|
@ -903,8 +903,20 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
|
|||
State.ParamDeclEnd => |ctx| {
|
||||
if (eatToken(&tok_it, &tree, Token.Id.Ellipsis3)) |ellipsis3| {
|
||||
ctx.param_decl.var_args_token = ellipsis3;
|
||||
stack.append(State{ .ExpectToken = Token.Id.RParen }) catch unreachable;
|
||||
continue;
|
||||
|
||||
switch (expectCommaOrEnd(&tok_it, &tree, Token.Id.RParen)) {
|
||||
ExpectCommaOrEndResult.end_token => |t| {
|
||||
if (t == null) {
|
||||
stack.append(State{ .ExpectToken = Token.Id.RParen }) catch unreachable;
|
||||
continue;
|
||||
}
|
||||
continue;
|
||||
},
|
||||
ExpectCommaOrEndResult.parse_error => |e| {
|
||||
try tree.errors.push(e);
|
||||
return tree;
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
try stack.append(State{ .ParamDeclComma = ctx.fn_proto });
|
||||
|
|
|
@ -354,6 +354,15 @@ test "zig fmt: fn decl with trailing comma" {
|
|||
);
|
||||
}
|
||||
|
||||
test "zig fmt: var_args with trailing comma" {
|
||||
try testCanonical(
|
||||
\\pub fn add(
|
||||
\\ a: ...,
|
||||
\\) void {}
|
||||
\\
|
||||
);
|
||||
}
|
||||
|
||||
test "zig fmt: enum decl with no trailing comma" {
|
||||
try testTransform(
|
||||
\\const StrLitKind = enum {Normal, C};
|
||||
|
|
Loading…
Reference in New Issue
Block a user