mirror of
https://codeberg.org/ziglang/zig.git
synced 2025-12-06 05:44:20 +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;
|
||||
}
|
||||
|
||||
fn writeStringLiteralAsIdentifier(r: *Render, token_index: Ast.TokenIndex) !usize {
|
||||
fn writeStringLiteralAsIdentifier(r: *Render, token_index: Ast.TokenIndex) Error!usize {
|
||||
const tree = r.tree;
|
||||
const ais = r.ais;
|
||||
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];
|
||||
if (std.zig.isValidId(unquoted)) {
|
||||
try ais.writeAll(unquoted);
|
||||
return unquoted.len;
|
||||
} else {
|
||||
try ais.writeByte('@');
|
||||
try ais.writeAll(lexeme);
|
||||
return lexeme.len + 1;
|
||||
}
|
||||
return lexeme.len;
|
||||
}
|
||||
|
||||
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" {
|
||||
try testError(
|
||||
\\test "" {inline}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue