Skip to content

Commit c339661

Browse files
committed
zig fmt / std.zig.Ast: count addrspace tokens correctly
1 parent 1914d1a commit c339661

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

lib/std/zig/Ast.zig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6074,6 +6074,16 @@ test "zig fmt: do not canonicalize invalid cast builtins" {
60746074
);
60756075
}
60766076

6077+
test "zig fmt: extern addrspace in struct" {
6078+
try testCanonical(
6079+
\\const namespace = struct {
6080+
\\ extern const num: u8 addrspace(.generic);
6081+
\\};
6082+
\\// comment
6083+
\\
6084+
);
6085+
}
6086+
60776087
test "recovery: top level" {
60786088
try testError(
60796089
\\test "" {inline}

0 commit comments

Comments
 (0)