authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-02-24 21:50:20-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-02-24 21:50:57-07:00
log9b8a94265ab7313f07b300ddc349a60c85d556d1
tree80ca48193b327cc749d404292878186399182627
parent5f35dc0c0d0530d5a1d028c56a763def3d1fd250

zig fmt: fix extern function with missing param name

Regressed in d7049fc8e0709619b8aa6766b37abeae946703b2.

2 files changed, 15 insertions(+), 2 deletions(-)

lib/std/zig/parser_test.zig+11
...@@ -4190,6 +4190,17 @@ test "zig fmt: function with labeled block as return type" {...@@ -4190,6 +4190,17 @@ test "zig fmt: function with labeled block as return type" {
4190 );4190 );
4191}4191}
41924192
4193test "zig fmt: extern function with missing param name" {
4194 try testCanonical(
4195 \\extern fn a(
4196 \\ *b,
4197 \\ c: *d,
4198 \\) e;
4199 \\extern fn f(*g, h: *i) j;
4200 \\
4201 );
4202}
4203
4193test "zig fmt: line comment after multiline single expr if statement with multiline string" {4204test "zig fmt: line comment after multiline single expr if statement with multiline string" {
4194 try testCanonical(4205 try testCanonical(
4195 \\test {4206 \\test {
lib/std/zig/render.zig+4-2
...@@ -1449,9 +1449,11 @@ fn renderFnProto(gpa: *Allocator, ais: *Ais, tree: ast.Tree, fn_proto: ast.full....@@ -1449,9 +1449,11 @@ fn renderFnProto(gpa: *Allocator, ais: *Ais, tree: ast.Tree, fn_proto: ast.full.
1449 continue;1449 continue;
1450 },1450 },
1451 .r_paren => break,1451 .r_paren => break,
1452 else => unreachable,1452 else => {}, // Parameter type without a name.
1453 }1453 }
1454 if (token_tags[last_param_token] == .identifier) {1454 if (token_tags[last_param_token] == .identifier and
1455 token_tags[last_param_token + 1] == .colon)
1456 {
1455 try renderToken(ais, tree, last_param_token, .none); // name1457 try renderToken(ais, tree, last_param_token, .none); // name
1456 last_param_token += 1;1458 last_param_token += 1;
1457 try renderToken(ais, tree, last_param_token, .space); // :1459 try renderToken(ais, tree, last_param_token, .space); // :