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:
parent
4e34edfa81
commit
6c022db786
@ -745,14 +745,16 @@ fn (mut s Scanner) text_scan() token.Token {
|
||||
}
|
||||
// Handle `'$fn()'`
|
||||
if c == `)` && s.is_inter_start {
|
||||
next_char := s.look_ahead(1)
|
||||
if next_char != `.` {
|
||||
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
|
||||
}
|
||||
return s.new_token(.rpar, '', 1)
|
||||
}
|
||||
}
|
||||
// all other tokens
|
||||
match c {
|
||||
`+` {
|
||||
|
@ -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<'
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user