authorgravatar for mail@isaacfreund.comIsaac Freund <mail@isaacfreund.com> 2021-02-10 19:19:58+01:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-02-10 11:53:53-08:00
log515d4920e79ca3c631f243f6a1d7fb6b48aa91cd
treeccfabf7bdf13af646ea5fd9e1d9340a109ecd1b1
parent5df7fc36c6e5d7caf7b5b5437bf40fec77a2b971

zig fmt: fix 0 element struct and array init


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

lib/std/zig/ast.zig+5-2
......@@ -796,8 +796,11 @@ pub const Tree = struct {
796796 .StructInitOne,
797797 => {
798798 end_offset += 1; // rbrace
799 n = datas[n].rhs;
800 assert(n != 0);
799 if (datas[n].rhs == 0) {
800 return main_tokens[n] + end_offset;
801 } else {
802 n = datas[n].rhs;
803 }
801804 },
802805 .SliceOpen,
803806 .CallOneComma,
lib/std/zig/parser_test.zig+27
......@@ -464,6 +464,15 @@ test "zig fmt: anon literal in array" {
464464// );
465465//}
466466
467test "zig fmt: anon struct literal 0 element" {
468 try testCanonical(
469 \\test {
470 \\ const x = .{};
471 \\}
472 \\
473 );
474}
475
467476test "zig fmt: anon struct literal 1 element" {
468477 try testCanonical(
469478 \\test {
......@@ -527,6 +536,15 @@ test "zig fmt: anon struct literal 3 element comma" {
527536 );
528537}
529538
539test "zig fmt: struct literal 0 element" {
540 try testCanonical(
541 \\test {
542 \\ const x = X{};
543 \\}
544 \\
545 );
546}
547
530548test "zig fmt: struct literal 1 element" {
531549 try testCanonical(
532550 \\test {
......@@ -653,6 +671,15 @@ test "zig fmt: anon list literal 3 element comma" {
653671 );
654672}
655673
674test "zig fmt: array literal 0 element" {
675 try testCanonical(
676 \\test {
677 \\ const x = [_]u32{};
678 \\}
679 \\
680 );
681}
682
656683test "zig fmt: array literal 1 element" {
657684 try testCanonical(
658685 \\test {