authorgravatar for rpkak@noreply.codeberg.orgrpkak <rpkak@noreply.codeberg.org> 2025-12-01 12:56:11+01:00
committergravatar for mail@isaacfreund.comIsaac Freund <mail@isaacfreund.com> 2025-12-01 12:56:11+01:00
log95f93a0b281e32583edef36808231a5f61fb7de1
tree3fa7aca3b719492a56fad4e0661b8efe02b4b6fd
parent1d1e2b77802c75b3abb793599aefe4c772a7cfb8

std.zig.Ast: count addrspace tokens correctly

Before this PR this ```zig const namespace = struct { extern const num: u8 addrspace(.generic); }; // comment ``` got formatted to this ```zig const namespace = struct { extern const num: u8 addrspace(.generic); ( ``` Co-authored-by: rpkak <rpkak@noreply.codeberg.org> Co-committed-by: rpkak <rpkak@noreply.codeberg.org>

2 files changed, 13 insertions(+), 0 deletions(-)

lib/std/zig/Ast.zig+3
......@@ -1195,6 +1195,9 @@ pub fn lastToken(tree: Ast, node: Node.Index) TokenIndex {
11951195 if (extra.section_node.unwrap()) |section_node| {
11961196 end_offset += 1; // for the rparen
11971197 n = section_node;
1198 } else if (extra.addrspace_node.unwrap()) |addrspace_node| {
1199 end_offset += 1; // for the rparen
1200 n = addrspace_node;
11981201 } else if (extra.align_node.unwrap()) |align_node| {
11991202 end_offset += 1; // for the rparen
12001203 n = align_node;
lib/std/zig/parser_test.zig+10
......@@ -6084,6 +6084,16 @@ test "zig fmt: do not canonicalize invalid cast builtins" {
60846084 );
60856085}
60866086
6087test "zig fmt: extern addrspace in struct" {
6088 try testCanonical(
6089 \\const namespace = struct {
6090 \\ extern const num: u8 addrspace(.generic);
6091 \\};
6092 \\// comment
6093 \\
6094 );
6095}
6096
60876097test "recovery: top level" {
60886098 try testError(
60896099 \\test "" {inline}