checker: fix missing check for escape char on unicode checker (#22462)

This commit is contained in:
Felipe Pena 2024-10-09 10:49:51 -03:00 committed by GitHub
parent 98f66d803a
commit 875faaff0f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 13 additions and 1 deletions

View File

@ -143,7 +143,10 @@ fn (mut c Checker) string_lit(mut node ast.StringLiteral) ast.Type {
start_idx := idx
idx++
next_ch := node.val[idx] or { return ast.string_type }
if next_ch == `u` {
if next_ch == `\\` {
// ignore escaping char
idx++
} else if next_ch == `u` {
idx++
mut ch := node.val[idx] or { return ast.string_type }
mut hex_char_count := 0

View File

@ -0,0 +1,9 @@
fn test_main() {
a := r'\u306aefgh\t'
mut expected := '\\u306a'
expected += 'efgh\\t'
assert a == expected
assert a == '\\u306aefgh\\t'
}