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:
parent
82db1e4746
commit
f619becbdc
@ -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
|
||||||
|
@ -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 |
|
@ -0,0 +1,9 @@
|
|||||||
|
fn abc() string {
|
||||||
|
return 'abc $type'
|
||||||
|
}
|
||||||
|
|
||||||
|
fn xyz() string {
|
||||||
|
return '42P01'
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {}
|
Loading…
Reference in New Issue
Block a user