From 160469cfcd36888420112103de5fb10693d37261 Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Tue, 14 Apr 2026 12:45:27 +0300 Subject: [PATCH] checker: Misleading or wrong error message in UTF-8 byte sequence verification (fixes #25874) --- vlib/v/checker/str.v | 2 +- vlib/v/checker/tests/invalid_utf8_escape_string.out | 5 +++++ vlib/v/checker/tests/invalid_utf8_escape_string.vv | 3 +++ vlib/v/checker/tests/invalid_utf8_string.out | 2 +- 4 files changed, 10 insertions(+), 2 deletions(-) create mode 100644 vlib/v/checker/tests/invalid_utf8_escape_string.out create mode 100644 vlib/v/checker/tests/invalid_utf8_escape_string.vv diff --git a/vlib/v/checker/str.v b/vlib/v/checker/str.v index ab46fcea7..f55e19c45 100644 --- a/vlib/v/checker/str.v +++ b/vlib/v/checker/str.v @@ -189,7 +189,7 @@ const unicode_lit_overflow_message = 'unicode character exceeds max allowed valu fn (mut c Checker) string_lit(mut node ast.StringLiteral) ast.Type { valid_utf8 := validate.utf8_string(node.val) if !valid_utf8 { - c.note("invalid utf8 string, please check your file's encoding is utf8", node.pos) + c.note('invalid utf8 byte sequence in string literal', node.pos) } mut idx := 0 for idx < node.val.len { diff --git a/vlib/v/checker/tests/invalid_utf8_escape_string.out b/vlib/v/checker/tests/invalid_utf8_escape_string.out new file mode 100644 index 000000000..965e7ae61 --- /dev/null +++ b/vlib/v/checker/tests/invalid_utf8_escape_string.out @@ -0,0 +1,5 @@ +vlib/v/checker/tests/invalid_utf8_escape_string.vv:2:22: notice: invalid utf8 byte sequence in string literal + 1 | fn main() { + 2 | println('\xF0\x81\xA0\x80') + | ~~~~~~ + 3 | } diff --git a/vlib/v/checker/tests/invalid_utf8_escape_string.vv b/vlib/v/checker/tests/invalid_utf8_escape_string.vv new file mode 100644 index 000000000..16deb72c1 --- /dev/null +++ b/vlib/v/checker/tests/invalid_utf8_escape_string.vv @@ -0,0 +1,3 @@ +fn main() { + println('\xF0\x81\xA0\x80') +} diff --git a/vlib/v/checker/tests/invalid_utf8_string.out b/vlib/v/checker/tests/invalid_utf8_string.out index 5ef205f82..4b628cb24 100644 --- a/vlib/v/checker/tests/invalid_utf8_string.out +++ b/vlib/v/checker/tests/invalid_utf8_string.out @@ -1,3 +1,3 @@ -vlib/v/checker/tests/invalid_utf8_string.vv:1:6: notice: invalid utf8 string, please check your file's encoding is utf8 +vlib/v/checker/tests/invalid_utf8_string.vv:1:6: notice: invalid utf8 byte sequence in string literal 1 | _ := '²âÊÔtxt' | ~~~~~~~ -- 2.39.5