mirror of
https://codeberg.org/ziglang/zig.git
synced 2025-12-06 13:54:21 +00:00
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.
This commit is contained in:
parent
15d830fd15
commit
a55e720d17
2 changed files with 15 additions and 3 deletions
|
|
@ -3673,7 +3673,7 @@ fn tokenSliceForRender(tree: Ast, token_index: Ast.TokenIndex) []const u8 {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn writeStringLiteralAsIdentifier(r: *Render, token_index: Ast.TokenIndex) !usize {
|
fn writeStringLiteralAsIdentifier(r: *Render, token_index: Ast.TokenIndex) Error!usize {
|
||||||
const tree = r.tree;
|
const tree = r.tree;
|
||||||
const ais = r.ais;
|
const ais = r.ais;
|
||||||
assert(tree.tokenTag(token_index) == .string_literal);
|
assert(tree.tokenTag(token_index) == .string_literal);
|
||||||
|
|
@ -3681,12 +3681,11 @@ fn writeStringLiteralAsIdentifier(r: *Render, token_index: Ast.TokenIndex) !usiz
|
||||||
const unquoted = lexeme[1..][0 .. lexeme.len - 2];
|
const unquoted = lexeme[1..][0 .. lexeme.len - 2];
|
||||||
if (std.zig.isValidId(unquoted)) {
|
if (std.zig.isValidId(unquoted)) {
|
||||||
try ais.writeAll(unquoted);
|
try ais.writeAll(unquoted);
|
||||||
return unquoted.len;
|
|
||||||
} else {
|
} else {
|
||||||
try ais.writeByte('@');
|
try ais.writeByte('@');
|
||||||
try ais.writeAll(lexeme);
|
try ais.writeAll(lexeme);
|
||||||
return lexeme.len + 1;
|
|
||||||
}
|
}
|
||||||
|
return lexeme.len;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn hasSameLineComment(tree: Ast, token_index: Ast.TokenIndex) bool {
|
fn hasSameLineComment(tree: Ast, token_index: Ast.TokenIndex) bool {
|
||||||
|
|
|
||||||
|
|
@ -6777,6 +6777,19 @@ test "zig fmt: canonicalize stray backslashes in identifiers" {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
test "zig fmt: asm_legacy conversion with quoted identifier" {
|
||||||
|
try testTransform(
|
||||||
|
\\const a = asm (x :: [L] "" (q) : "");
|
||||||
|
,
|
||||||
|
\\const a = asm (x
|
||||||
|
\\ :
|
||||||
|
\\ : [L] "" (q),
|
||||||
|
\\ : .{ .@"" = true }
|
||||||
|
\\);
|
||||||
|
\\
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
test "recovery: top level" {
|
test "recovery: top level" {
|
||||||
try testError(
|
try testError(
|
||||||
\\test "" {inline}
|
\\test "" {inline}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue