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 {...@@ -796,8 +796,11 @@ pub const Tree = struct {
796 .StructInitOne,796 .StructInitOne,
797 => {797 => {
798 end_offset += 1; // rbrace798 end_offset += 1; // rbrace
799 n = datas[n].rhs;799 if (datas[n].rhs == 0) {
800 assert(n != 0);800 return main_tokens[n] + end_offset;
801 } else {
802 n = datas[n].rhs;
803 }
801 },804 },
802 .SliceOpen,805 .SliceOpen,
803 .CallOneComma,806 .CallOneComma,
lib/std/zig/parser_test.zig+27
...@@ -464,6 +464,15 @@ test "zig fmt: anon literal in array" {...@@ -464,6 +464,15 @@ test "zig fmt: anon literal in array" {
464// );464// );
465//}465//}
466466
467test "zig fmt: anon struct literal 0 element" {
468 try testCanonical(
469 \\test {
470 \\ const x = .{};
471 \\}
472 \\
473 );
474}
475
467test "zig fmt: anon struct literal 1 element" {476test "zig fmt: anon struct literal 1 element" {
468 try testCanonical(477 try testCanonical(
469 \\test {478 \\test {
...@@ -527,6 +536,15 @@ test "zig fmt: anon struct literal 3 element comma" {...@@ -527,6 +536,15 @@ test "zig fmt: anon struct literal 3 element comma" {
527 );536 );
528}537}
529538
539test "zig fmt: struct literal 0 element" {
540 try testCanonical(
541 \\test {
542 \\ const x = X{};
543 \\}
544 \\
545 );
546}
547
530test "zig fmt: struct literal 1 element" {548test "zig fmt: struct literal 1 element" {
531 try testCanonical(549 try testCanonical(
532 \\test {550 \\test {
...@@ -653,6 +671,15 @@ test "zig fmt: anon list literal 3 element comma" {...@@ -653,6 +671,15 @@ test "zig fmt: anon list literal 3 element comma" {
653 );671 );
654}672}
655673
674test "zig fmt: array literal 0 element" {
675 try testCanonical(
676 \\test {
677 \\ const x = [_]u32{};
678 \\}
679 \\
680 );
681}
682
656test "zig fmt: array literal 1 element" {683test "zig fmt: array literal 1 element" {
657 try testCanonical(684 try testCanonical(
658 \\test {685 \\test {