Skip to content

Commit 70c335b

Browse files
committed
zig fmt: fix asm_legacy conversion with quoted identifier
renderSpace takes the length of the original lexeme, so passing the length of the new lexeme is not correct.
1 parent dda2f72 commit 70c335b

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

lib/std/zig/Ast/Render.zig

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3632,20 +3632,19 @@ fn tokenSliceForRender(tree: Ast, token_index: Ast.TokenIndex) []const u8 {
36323632
return ret;
36333633
}
36343634

3635-
fn writeStringLiteralAsIdentifier(r: *Render, token_index: Ast.TokenIndex) !usize {
3635+
fn writeStringLiteralAsIdentifier(r: *Render, token_index: Ast.TokenIndex) Error!usize {
36363636
const tree = r.tree;
36373637
const ais = r.ais;
36383638
assert(tree.tokenTag(token_index) == .string_literal);
36393639
const lexeme = tokenSliceForRender(tree, token_index);
36403640
const unquoted = lexeme[1..][0 .. lexeme.len - 2];
36413641
if (std.zig.isValidId(unquoted)) {
36423642
try ais.writeAll(unquoted);
3643-
return unquoted.len;
36443643
} else {
36453644
try ais.writeByte('@');
36463645
try ais.writeAll(lexeme);
3647-
return lexeme.len + 1;
36483646
}
3647+
return lexeme.len;
36493648
}
36503649

36513650
fn hasSameLineComment(tree: Ast, token_index: Ast.TokenIndex) bool {

lib/std/zig/parser_test.zig

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6739,6 +6739,19 @@ test "zig fmt: canonicalize stray backslashes in identifiers" {
67396739
);
67406740
}
67416741

6742+
test "zig fmt: asm_legacy conversion with quoted identifier" {
6743+
try testTransform(
6744+
\\const a = asm (x :: [L] "" (q) : "");
6745+
,
6746+
\\const a = asm (x
6747+
\\ :
6748+
\\ : [L] "" (q),
6749+
\\ : .{ .@"" = true }
6750+
\\);
6751+
\\
6752+
);
6753+
}
6754+
67426755
test "recovery: top level" {
67436756
try testError(
67446757
\\test "" {inline}

0 commit comments

Comments
 (0)