authorgravatar for goon.pri.low@gmail.comKendall Condon <goon.pri.low@gmail.com> 2025-07-28 14:10:18-04:00
committergravatar for goon.pri.low@gmail.comKendall Condon <goon.pri.low@gmail.com> 2026-03-12 17:23:23-04:00
log409541bc77cb1d6a447dbcdf74f9fcbc2a8b0397
tree6d4b9751fddb9162e88749fe8b8085e5ca5be403
parentbbc2e7a74da98cfcf7bd24f1904cc77a203002f8

zig fmt: canonicalize stray backslashes in identifiers


2 files changed, 21 insertions(+), 0 deletions(-)

lib/std/zig/Ast/Render.zig+3
......@@ -3257,6 +3257,9 @@ fn renderIdentifierContents(ais: *AutoIndentingStream, bytes: []const u8) !void
32573257 }
32583258 },
32593259 .failure => {
3260 // Escape the stray backslash
3261 // This also avoids cases like "\x3\x39" becoming "\x39"
3262 try ais.writeByte('\\');
32603263 try ais.writeAll(escape_sequence);
32613264 },
32623265 }
lib/std/zig/parser_test.zig+18
......@@ -6666,6 +6666,24 @@ test "zig fmt: doc comments on fn parameters" {
66666666 );
66676667}
66686668
6669test "zig fmt: canonicalize stray backslashes in identifiers" {
6670 try testTransform(
6671 \\const @"\x" = undefined;
6672 \\const @"\x3" = undefined;
6673 \\const @"\x3\x39" = undefined;
6674 \\const @"\u{" = undefined;
6675 \\const @"\?" = undefined;
6676 \\
6677 ,
6678 \\const @"\\x" = undefined;
6679 \\const @"\\x3" = undefined;
6680 \\const @"\\x39" = undefined;
6681 \\const @"\\u{" = undefined;
6682 \\const @"\\?" = undefined;
6683 \\
6684 );
6685}
6686
66696687test "recovery: top level" {
66706688 try testError(
66716689 \\test "" {inline}