diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2021-02-24 21:50:20 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2021-02-24 21:50:57 -0700 |
| commit | 9b8a94265ab7313f07b300ddc349a60c85d556d1 (patch) | |
| tree | 80ca48193b327cc749d404292878186399182627 /lib/std | |
| parent | 5f35dc0c0d0530d5a1d028c56a763def3d1fd250 (diff) | |
| download | zig-9b8a94265ab7313f07b300ddc349a60c85d556d1.tar.gz zig-9b8a94265ab7313f07b300ddc349a60c85d556d1.zip | |
zig fmt: fix extern function with missing param name
Regressed in d7049fc8e0709619b8aa6766b37abeae946703b2.
Diffstat (limited to 'lib/std')
| -rw-r--r-- | lib/std/zig/parser_test.zig | 11 | ||||
| -rw-r--r-- | lib/std/zig/render.zig | 6 |
2 files changed, 15 insertions, 2 deletions
diff --git a/lib/std/zig/parser_test.zig b/lib/std/zig/parser_test.zig index 4ec527fd6c..2b9e3fb03c 100644 --- a/lib/std/zig/parser_test.zig +++ b/lib/std/zig/parser_test.zig @@ -4190,6 +4190,17 @@ test "zig fmt: function with labeled block as return type" { ); } +test "zig fmt: extern function with missing param name" { + try testCanonical( + \\extern fn a( + \\ *b, + \\ c: *d, + \\) e; + \\extern fn f(*g, h: *i) j; + \\ + ); +} + test "zig fmt: line comment after multiline single expr if statement with multiline string" { try testCanonical( \\test { diff --git a/lib/std/zig/render.zig b/lib/std/zig/render.zig index 673a05f8e6..e12f7bc733 100644 --- a/lib/std/zig/render.zig +++ b/lib/std/zig/render.zig @@ -1449,9 +1449,11 @@ fn renderFnProto(gpa: *Allocator, ais: *Ais, tree: ast.Tree, fn_proto: ast.full. continue; }, .r_paren => break, - else => unreachable, + else => {}, // Parameter type without a name. } - if (token_tags[last_param_token] == .identifier) { + if (token_tags[last_param_token] == .identifier and + token_tags[last_param_token + 1] == .colon) + { try renderToken(ais, tree, last_param_token, .none); // name last_param_token += 1; try renderToken(ais, tree, last_param_token, .space); // : |
