zig fmt / std.zig.Ast: count addrspace tokens correctly

This commit is contained in:
rpkak 2025-11-27 08:47:31 +01:00
parent 854774d468
commit 7f433ed813
2 changed files with 13 additions and 0 deletions

View file

@ -1195,6 +1195,9 @@ pub fn lastToken(tree: Ast, node: Node.Index) TokenIndex {
if (extra.section_node.unwrap()) |section_node| { if (extra.section_node.unwrap()) |section_node| {
end_offset += 1; // for the rparen end_offset += 1; // for the rparen
n = section_node; n = section_node;
} else if (extra.addrspace_node.unwrap()) |addrspace_node| {
end_offset += 1; // for the rparen
n = addrspace_node;
} else if (extra.align_node.unwrap()) |align_node| { } else if (extra.align_node.unwrap()) |align_node| {
end_offset += 1; // for the rparen end_offset += 1; // for the rparen
n = align_node; n = align_node;

View file

@ -6084,6 +6084,16 @@ test "zig fmt: do not canonicalize invalid cast builtins" {
); );
} }
test "zig fmt: extern addrspace in struct" {
try testCanonical(
\\const namespace = struct {
\\ extern const num: u8 addrspace(.generic);
\\};
\\// comment
\\
);
}
test "recovery: top level" { test "recovery: top level" {
try testError( try testError(
\\test "" {inline} \\test "" {inline}