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;