From ef3adbdb362d5511b05543567c58c5bdfb0cf093 Mon Sep 17 00:00:00 2001 From: Isaac Freund Date: Fri, 5 Mar 2021 12:29:02 +0100 Subject: [PATCH] zig fmt: fix lastToken() for container_decl_arg --- lib/std/zig/ast.zig | 2 +- lib/std/zig/parser_test.zig | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/lib/std/zig/ast.zig b/lib/std/zig/ast.zig index 46b58e9465..1a0515b475 100644 --- a/lib/std/zig/ast.zig +++ b/lib/std/zig/ast.zig @@ -766,7 +766,7 @@ pub const Tree = struct { .container_decl_arg => { const members = tree.extraData(datas[n].rhs, Node.SubRange); if (members.end - members.start == 0) { - end_offset += 1; // for the rparen + end_offset += 3; // for the rparen + lbrace + rbrace n = datas[n].lhs; } else { end_offset += 1; // for the rbrace diff --git a/lib/std/zig/parser_test.zig b/lib/std/zig/parser_test.zig index 42849166eb..f4b95f2362 100644 --- a/lib/std/zig/parser_test.zig +++ b/lib/std/zig/parser_test.zig @@ -963,6 +963,27 @@ test "zig fmt: allowzero pointer" { ); } +test "zig fmt: empty enum decls" { + try testCanonical( + \\const A = enum {}; + \\const B = enum(u32) {}; + \\const C = extern enum(c_int) {}; + \\const D = packed enum(u8) {}; + \\ + ); +} + +test "zig fmt: empty union decls" { + try testCanonical( + \\const A = union {}; + \\const B = union(enum) {}; + \\const C = union(Foo) {}; + \\const D = extern union {}; + \\const E = packed union {}; + \\ + ); +} + test "zig fmt: enum literal" { try testCanonical( \\const x = .hi;