Lyricdev
GitHub

LYR-LEX0013

a byte escape in a string or character

error · spec 01-lexical

A string, character literal or f-string holds the escape \xNN, which writes a byte and stands in a byte string b"…" only.

Explanation

\xNN writes one byte. In a string it would name a character by a byte, which reads like UTF-8 and is not: "\xC3" is no part of é. A character is written \u{…}.

Write the character as \u{…}, or use a byte string when bytes are meant.

Wrong

fn main(): void {
    let s = "\x41";
    let _ = s;
}
fn main(): void {
    let s = "\u{41}";
    let _ = s;
}