authorgravatar for mail@isaacfreund.comIsaac Freund <mail@isaacfreund.com> 2021-02-11 22:31:44+01:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-02-11 15:49:49-08:00
logb6448a533d4465c226b7b8613806ff0673261d6a
treee4e50873616f6165ed0703a09cd0fce3d143f6ce
parent4c8caf33437d8ce55450a51dfbf89db69c65680e

zig fmt: fix Tree.lastToken() for empty *Two nodes


1 files changed, 13 insertions(+), 12 deletions(-)

lib/std/zig/ast.zig+13-12
......@@ -676,20 +676,11 @@ pub const Tree = struct {
676676 },
677677 .ArrayInitDotTwo,
678678 .BlockTwo,
679 .BuiltinCallTwo,
679680 .StructInitDotTwo,
680681 .ContainerDeclTwo,
681682 .TaggedUnionTwo,
682683 => {
683 end_offset += 1; // for the rparen/rbrace
684 if (datas[n].rhs != 0) {
685 n = datas[n].rhs;
686 } else if (datas[n].lhs != 0) {
687 n = datas[n].lhs;
688 } else {
689 return main_tokens[n] + end_offset;
690 }
691 },
692 .BuiltinCallTwo => {
693684 if (datas[n].rhs != 0) {
694685 end_offset += 1; // for the rparen/rbrace
695686 n = datas[n].rhs;
......@@ -697,7 +688,17 @@ pub const Tree = struct {
697688 end_offset += 1; // for the rparen/rbrace
698689 n = datas[n].lhs;
699690 } else {
700 end_offset += 2; // for the lparen and rparen
691 switch (tags[n]) {
692 .ArrayInitDotTwo,
693 .BlockTwo,
694 .StructInitDotTwo,
695 => end_offset += 1, // rbrace
696 .BuiltinCallTwo,
697 .ContainerDeclTwo,
698 => end_offset += 2, // lparen/lbrace + rparen/rbrace
699 .TaggedUnionTwo => end_offset += 5, // (enum) {}
700 else => unreachable,
701 }
701702 return main_tokens[n] + end_offset;
702703 }
703704 },
......@@ -2708,7 +2709,7 @@ pub const Node = struct {
27082709 /// `{}`. `sub_list[lhs..rhs]`.
27092710 /// main_token points at the lbrace.
27102711 Block,
2711 /// Same as BlockTwo but there is known to be a semicolon before the rbrace.
2712 /// Same as Block but there is known to be a semicolon before the rbrace.
27122713 BlockSemicolon,
27132714 /// `asm(lhs)`. rhs is the token index of the rparen.
27142715 AsmSimple,