From b6448a533d4465c226b7b8613806ff0673261d6a Mon Sep 17 00:00:00 2001 From: Isaac Freund Date: Thu, 11 Feb 2021 22:31:44 +0100 Subject: [PATCH] zig fmt: fix Tree.lastToken() for empty *Two nodes --- lib/std/zig/ast.zig | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/lib/std/zig/ast.zig b/lib/std/zig/ast.zig index 783a578e01..ad96baf3f3 100644 --- a/lib/std/zig/ast.zig +++ b/lib/std/zig/ast.zig @@ -676,20 +676,11 @@ pub const Tree = struct { }, .ArrayInitDotTwo, .BlockTwo, + .BuiltinCallTwo, .StructInitDotTwo, .ContainerDeclTwo, .TaggedUnionTwo, => { - end_offset += 1; // for the rparen/rbrace - if (datas[n].rhs != 0) { - n = datas[n].rhs; - } else if (datas[n].lhs != 0) { - n = datas[n].lhs; - } else { - return main_tokens[n] + end_offset; - } - }, - .BuiltinCallTwo => { if (datas[n].rhs != 0) { end_offset += 1; // for the rparen/rbrace n = datas[n].rhs; @@ -697,7 +688,17 @@ pub const Tree = struct { end_offset += 1; // for the rparen/rbrace n = datas[n].lhs; } else { - end_offset += 2; // for the lparen and rparen + switch (tags[n]) { + .ArrayInitDotTwo, + .BlockTwo, + .StructInitDotTwo, + => end_offset += 1, // rbrace + .BuiltinCallTwo, + .ContainerDeclTwo, + => end_offset += 2, // lparen/lbrace + rparen/rbrace + .TaggedUnionTwo => end_offset += 5, // (enum) {} + else => unreachable, + } return main_tokens[n] + end_offset; } }, @@ -2708,7 +2709,7 @@ pub const Node = struct { /// `{}`. `sub_list[lhs..rhs]`. /// main_token points at the lbrace. Block, - /// Same as BlockTwo but there is known to be a semicolon before the rbrace. + /// Same as Block but there is known to be a semicolon before the rbrace. BlockSemicolon, /// `asm(lhs)`. rhs is the token index of the rparen. AsmSimple,