authorgravatar for jacoblevgw@gmail.comJacob G-W <jacoblevgw@gmail.com> 2021-06-03 22:30:31-04:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2021-06-04 10:49:05+03:00
log5d94e754f4159277a2cef98d0c4226bab0e697a3
tree93d5ab4d839dff7a439a2299b952352fa8b9cb3e
parent83e0a49ba4938fb90b27c01ce9adc3dbe2984164

fmt: fix #8974

also add a regression test

2 files changed, 18 insertions(+), 9 deletions(-)

lib/std/zig/parser_test.zig+7
......@@ -4409,6 +4409,13 @@ test "zig fmt: regression test for #5722" {
44094409 );
44104410}
44114411
4412test "zig fmt: regression test for #8974" {
4413 try testCanonical(
4414 \\pub const VARIABLE;
4415 \\
4416 );
4417}
4418
44124419test "zig fmt: allow trailing line comments to do manual array formatting" {
44134420 try testCanonical(
44144421 \\fn foo() void {
lib/std/zig/render.zig+11-9
......@@ -989,16 +989,18 @@ fn renderVarDecl(gpa: *Allocator, ais: *Ais, tree: ast.Tree, var_decl: ast.full.
989989 }
990990 }
991991
992 assert(var_decl.ast.init_node != 0);
993 const eq_token = tree.firstToken(var_decl.ast.init_node) - 1;
994 const eq_space: Space = if (tree.tokensOnSameLine(eq_token, eq_token + 1)) .space else .newline;
995 {
996 ais.pushIndent();
997 try renderToken(ais, tree, eq_token, eq_space); // =
998 ais.popIndent();
992 if (var_decl.ast.init_node != 0) {
993 const eq_token = tree.firstToken(var_decl.ast.init_node) - 1;
994 const eq_space: Space = if (tree.tokensOnSameLine(eq_token, eq_token + 1)) .space else .newline;
995 {
996 ais.pushIndent();
997 try renderToken(ais, tree, eq_token, eq_space); // =
998 ais.popIndent();
999 }
1000 ais.pushIndentOneShot();
1001 return renderExpression(gpa, ais, tree, var_decl.ast.init_node, .semicolon); // ;
9991002 }
1000 ais.pushIndentOneShot();
1001 try renderExpression(gpa, ais, tree, var_decl.ast.init_node, .semicolon);
1003 return renderToken(ais, tree, var_decl.ast.mut_token + 2, .newline); // ;
10021004}
10031005
10041006fn renderIf(gpa: *Allocator, ais: *Ais, tree: ast.Tree, if_node: ast.full.If, space: Space) Error!void {