1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

scanner: correct error message of empty character literal (fix #15226) (#15228)

This commit is contained in:
yuyi 2022-07-26 20:07:08 +08:00 committed by GitHub
parent 4ab72ccb69
commit c976a691ad
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 0 deletions

View File

@ -1412,6 +1412,10 @@ fn (mut s Scanner) ident_char() string {
if u.len != 1 {
if escaped_hex || escaped_unicode {
s.error('invalid character literal `$orig` => `$c` ($u) (escape sequence did not refer to a singular rune)')
} else if u.len == 0 {
s.add_error_detail_with_pos('use quotes for strings, backticks for characters',
lspos)
s.error('invalid empty character literal `$orig`')
} else {
s.add_error_detail_with_pos('use quotes for strings, backticks for characters',
lspos)

View File

@ -0,0 +1,12 @@
vlib/v/scanner/tests/empty_character_literal_err.vv:2:8: error: invalid empty character literal ``
1 | fn main() {
2 | a := ``
| ^
3 | println(a)
4 | }
vlib/v/scanner/tests/empty_character_literal_err.vv:2:7: details: use quotes for strings, backticks for characters
1 | fn main() {
2 | a := ``
| ^
3 | println(a)
4 | }

View File

@ -0,0 +1,4 @@
fn main() {
a := ``
println(a)
}