Commit ef3adbdb36

Isaac Freund <ifreund@ifreund.xyz>
2021-03-05 12:29:02
zig fmt: fix lastToken() for container_decl_arg
1 parent 9cd038d
Changed files (2)
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
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;