diff --git a/vlib/v/scanner/scanner.v b/vlib/v/scanner/scanner.v index e30c15cb3c..a225fe0d65 100644 --- a/vlib/v/scanner/scanner.v +++ b/vlib/v/scanner/scanner.v @@ -666,7 +666,8 @@ fn (mut s Scanner) text_scan() token.Token { // Check if not .eof to prevent panic next_char := s.look_ahead(1) 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) } // 'asdf $b' => "b" is the last name in the string, dont start parsing string diff --git a/vlib/v/scanner/tests/undefined_ident_in_string_literal_err.out b/vlib/v/scanner/tests/undefined_ident_in_string_literal_err.out new file mode 100644 index 0000000000..b6054ac8f0 --- /dev/null +++ b/vlib/v/scanner/tests/undefined_ident_in_string_literal_err.out @@ -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 | diff --git a/vlib/v/scanner/tests/undefined_ident_in_string_literal_err.vv b/vlib/v/scanner/tests/undefined_ident_in_string_literal_err.vv new file mode 100644 index 0000000000..7dce13f95d --- /dev/null +++ b/vlib/v/scanner/tests/undefined_ident_in_string_literal_err.vv @@ -0,0 +1,9 @@ +fn abc() string { + return 'abc $type' +} + +fn xyz() string { + return '42P01' +} + +fn main() {}