diff --git a/vlib/v/scanner/scanner.v b/vlib/v/scanner/scanner.v index 18f8e9a6f8..df18c22bfd 100644 --- a/vlib/v/scanner/scanner.v +++ b/vlib/v/scanner/scanner.v @@ -46,7 +46,8 @@ pub mut: is_print_rel_paths_on_error bool quote u8 // which quote is used to denote current string: ' or " inter_quote u8 - nr_lines int // total number of lines in the source file that were scanned + just_closed_inter bool // if is_enclosed_inter was set to false on the previous character: `}` + nr_lines int // total number of lines in the source file that were scanned is_vh bool // Keep newlines is_fmt bool // Used for v fmt. comments_mode CommentsMode @@ -836,6 +837,7 @@ fn (mut s Scanner) text_scan() token.Token { return s.new_token(.string, '', 1) } s.is_enclosed_inter = false + s.just_closed_inter = true ident_string := s.ident_string() return s.new_token(.string, ident_string, ident_string.len + 2) // + two quotes } else { @@ -1149,13 +1151,16 @@ fn (mut s Scanner) ident_string() string { is_quote := q == scanner.single_quote || q == scanner.double_quote is_raw := is_quote && s.pos > 0 && s.text[s.pos - 1] == `r` && !s.is_inside_string is_cstr := is_quote && s.pos > 0 && s.text[s.pos - 1] == `c` && !s.is_inside_string - if is_quote { + // don't interpret quote as "start of string" quote when a string interpolation has + // just ended on the previous character meaning it's not the start of a new string + if is_quote && !s.just_closed_inter { if s.is_inside_string || s.is_enclosed_inter || s.is_inter_start { s.inter_quote = q } else { s.quote = q } } + s.just_closed_inter = false mut n_cr_chars := 0 mut start := s.pos start_char := s.text[start] diff --git a/vlib/v/tests/string_interpolation_string_args_test.v b/vlib/v/tests/string_interpolation_string_args_test.v index 0081f7279b..5b6579f5cb 100644 --- a/vlib/v/tests/string_interpolation_string_args_test.v +++ b/vlib/v/tests/string_interpolation_string_args_test.v @@ -28,4 +28,6 @@ fn test_interpolation_string_args() { assert '1_${show_more_info('aaa', '111')} 2_${show_more_info('bbb', '222')}' == '1_aaa111 2_bbb222' assert '1_${show_more_info('aaa', '111')} 2_${show_more_info('bbb', '222')}' == '1_aaa111 2_bbb222' + + assert '"${show_info('abc')}"' == '"abc"' }