diff --git a/vlib/v/scanner/scanner.v b/vlib/v/scanner/scanner.v index 67540cb0c2..18f35a764d 100644 --- a/vlib/v/scanner/scanner.v +++ b/vlib/v/scanner/scanner.v @@ -648,7 +648,7 @@ fn (mut s Scanner) text_scan() token.Token { } // End of $var, start next string if s.is_inter_end { - if s.text[s.pos] == s.quote { + if s.text[s.pos] == s.quote || (s.text[s.pos] == s.inter_quote && s.is_enclosed_inter) { s.is_inter_end = false return s.new_token(.string, '', 1) } diff --git a/vlib/v/tests/string_interpolation_with_inner_quotes_test.v b/vlib/v/tests/string_interpolation_with_inner_quotes_test.v new file mode 100644 index 0000000000..866bc0e2a7 --- /dev/null +++ b/vlib/v/tests/string_interpolation_with_inner_quotes_test.v @@ -0,0 +1,32 @@ +fn f(x int, s string) string { + return 'label ${s}: ${x}' +} + +// vfmt off +fn test_string_interp_with_inner_quotes() { + x := 'hi' + println('abc ${f(123, 'def')} xyz') + assert 'abc ${f(123, 'def')} xyz' == 'abc label def: 123 xyz' + + println('abc ${f(123, "def")} xyz') + assert 'abc ${f(123, "def")} xyz' == 'abc label def: 123 xyz' + + println("abc ${f(123, 'def')} xyz") + assert "abc ${f(123, 'def')} xyz" == 'abc label def: 123 xyz' + + println("abc ${f(123, "def")} xyz") + assert "abc ${f(123, "def")} xyz" == 'abc label def: 123 xyz' + + println("abc ${f(123, "$x $x")} xyz") + assert "abc ${f(123, "$x $x")} xyz" == 'abc label hi hi: 123 xyz' + + println('abc ${f(123, '$x $x')} xyz') + assert 'abc ${f(123, '$x $x')} xyz' == 'abc label hi hi: 123 xyz' + + println('abc ${f(123, "$x $x")} xyz') + assert 'abc ${f(123, "$x $x")} xyz' == 'abc label hi hi: 123 xyz' + + println("abc ${f(123, '$x $x')} xyz") + assert "abc ${f(123, '$x $x')} xyz" == 'abc label hi hi: 123 xyz' +} +// vfmt on