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

scanner: fix string interpolation for '$a.b().c' (#5612)

This commit is contained in:
Uwe Krüger 2020-07-02 00:02:59 +02:00 committed by GitHub
parent 4e34edfa81
commit 6c022db786
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 5 deletions

View File

@ -745,13 +745,15 @@ fn (mut s Scanner) text_scan() token.Token {
}
// Handle `'$fn()'`
if c == `)` && s.is_inter_start {
s.is_inter_end = true
s.is_inter_start = false
next_char := s.look_ahead(1)
if next_char == s.quote {
s.is_inside_string = false
if next_char != `.` {
s.is_inter_end = true
s.is_inter_start = false
if next_char == s.quote {
s.is_inside_string = false
}
return s.new_token(.rpar, '', 1)
}
return s.new_token(.rpar, '', 1)
}
// all other tokens
match c {

View File

@ -160,3 +160,25 @@ fn test_string_interpolation_with_negative_format_width_should_compile_and_run_w
eprintln('---------------------------------------------------------------------------------------------')
assert true
}
struct Aa {
a int
}
struct Bb {
b Aa
}
fn (x Bb) f() Aa {
return x.b
}
fn test_method_interpolation() {
y := Bb{
b: Aa{
a: 2
}
}
assert '>${y.f().a}<' == '>2<'
assert '>$y.f().a<' == '>2<'
}