diff options
| author | Isaac Freund <ifreund@ifreund.xyz> | 2021-03-05 12:29:02 +0100 |
|---|---|---|
| committer | Isaac Freund <ifreund@ifreund.xyz> | 2021-03-05 21:33:27 +0100 |
| commit | ef3adbdb362d5511b05543567c58c5bdfb0cf093 (patch) | |
| tree | 7a8da7dbc02462cfdc8dd014cbf14ecccd34d04b /lib/std | |
| parent | 9cd038d73a174706ec0a51ab9db0c04b095e019d (diff) | |
| download | zig-ef3adbdb362d5511b05543567c58c5bdfb0cf093.tar.gz zig-ef3adbdb362d5511b05543567c58c5bdfb0cf093.zip | |
zig fmt: fix lastToken() for container_decl_arg
Diffstat (limited to 'lib/std')
| -rw-r--r-- | lib/std/zig/ast.zig | 2 | ||||
| -rw-r--r-- | lib/std/zig/parser_test.zig | 21 |
2 files changed, 22 insertions, 1 deletions
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; |
