mirror of
https://github.com/vlang/v.git
synced 2025-09-14 23:12:33 +03:00
compiler: fix generation of default .str() methods in interpolation
This commit is contained in:
parent
09d9dd2607
commit
d2ab9d3e77
6 changed files with 136 additions and 14 deletions
|
@ -114,15 +114,10 @@ fn (p mut Parser) string_expr() {
|
|||
else {
|
||||
f := p.typ_to_fmt(typ, 0)
|
||||
if f == '' {
|
||||
is_array := typ.starts_with('array_')
|
||||
typ2 := p.table.find_type(typ)
|
||||
has_str_method := p.table.type_has_method(typ2, 'str')
|
||||
if is_array || has_str_method {
|
||||
if is_array && !has_str_method {
|
||||
p.gen_array_str(typ2)
|
||||
}
|
||||
has_str_method, styp := p.gen_default_str_method_if_missing( typ )
|
||||
if has_str_method {
|
||||
tmp_var := p.get_tmp()
|
||||
p.cgen.insert_before('string $tmp_var = ${typ}_str(${val});')
|
||||
p.cgen.insert_before('string $tmp_var = ${styp}_str(${val});')
|
||||
args = args.all_before_last(val) + '${tmp_var}.len, ${tmp_var}.str'
|
||||
format += '%.*s '
|
||||
}
|
||||
|
@ -137,7 +132,7 @@ fn (p mut Parser) string_expr() {
|
|||
if complex_inter {
|
||||
p.fgen('}')
|
||||
}
|
||||
|
||||
|
||||
// p.fgen('\'')
|
||||
// println("hello %d", num) optimization.
|
||||
if p.cgen.nogen {
|
||||
|
@ -165,4 +160,3 @@ fn (p mut Parser) string_expr() {
|
|||
p.gen('_STR($format$args)')
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue