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" {...@@ -4409,6 +4409,13 @@ test "zig fmt: regression test for #5722" {
4409 );4409 );
4410}4410}
44114411
4412test "zig fmt: regression test for #8974" {
4413 try testCanonical(
4414 \\pub const VARIABLE;
4415 \\
4416 );
4417}
4418
4412test "zig fmt: allow trailing line comments to do manual array formatting" {4419test "zig fmt: allow trailing line comments to do manual array formatting" {
4413 try testCanonical(4420 try testCanonical(
4414 \\fn foo() void {4421 \\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....@@ -989,16 +989,18 @@ fn renderVarDecl(gpa: *Allocator, ais: *Ais, tree: ast.Tree, var_decl: ast.full.
989 }989 }
990 }990 }
991991
992 assert(var_decl.ast.init_node != 0);992 if (var_decl.ast.init_node != 0) {
993 const eq_token = tree.firstToken(var_decl.ast.init_node) - 1;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;994 const eq_space: Space = if (tree.tokensOnSameLine(eq_token, eq_token + 1)) .space else .newline;
995 {995 {
996 ais.pushIndent();996 ais.pushIndent();
997 try renderToken(ais, tree, eq_token, eq_space); // =997 try renderToken(ais, tree, eq_token, eq_space); // =
998 ais.popIndent();998 ais.popIndent();
999 }
1000 ais.pushIndentOneShot();
1001 return renderExpression(gpa, ais, tree, var_decl.ast.init_node, .semicolon); // ;
999 }1002 }
1000 ais.pushIndentOneShot();1003 return renderToken(ais, tree, var_decl.ast.mut_token + 2, .newline); // ;
1001 try renderExpression(gpa, ais, tree, var_decl.ast.init_node, .semicolon);
1002}1004}
10031005
1004fn renderIf(gpa: *Allocator, ais: *Ais, tree: ast.Tree, if_node: ast.full.If, space: Space) Error!void {1006fn renderIf(gpa: *Allocator, ais: *Ais, tree: ast.Tree, if_node: ast.full.If, space: Space) Error!void {