mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
compiler: fix generation of default .str() methods in interpolation
This commit is contained in:
@@ -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)')
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user