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

scanner: check undefined ident in string literal (#15212)

This commit is contained in:
yuyi 2022-07-25 19:28:47 +08:00 committed by GitHub
parent 82db1e4746
commit f619becbdc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 1 deletions

View File

@ -666,7 +666,8 @@ fn (mut s Scanner) text_scan() token.Token {
// Check if not .eof to prevent panic // Check if not .eof to prevent panic
next_char := s.look_ahead(1) next_char := s.look_ahead(1)
kind := token.scanner_matcher.find(name) kind := token.scanner_matcher.find(name)
if kind != -1 { // '$type' '$struct'... will be recognized as ident (not keyword token)
if kind != -1 && !(s.is_inter_start && next_char == s.quote) {
return s.new_token(token.Kind(kind), name, name.len) return s.new_token(token.Kind(kind), name, name.len)
} }
// 'asdf $b' => "b" is the last name in the string, dont start parsing string // 'asdf $b' => "b" is the last name in the string, dont start parsing string

View File

@ -0,0 +1,6 @@
vlib/v/scanner/tests/undefined_ident_in_string_literal_err.vv:2:15: error: undefined ident: `type`
1 | fn abc() string {
2 | return 'abc $type'
| ~~~~
3 | }
4 |

View File

@ -0,0 +1,9 @@
fn abc() string {
return 'abc $type'
}
fn xyz() string {
return '42P01'
}
fn main() {}