parser: interpolation calling twice fix

if string interpolation needs to call a function, it will cache the
return to .len & .str usage in the generated code
pull/2385/head
Vinicius Rangel 2019-10-17 01:02:02 -03:00 committed by Alexander Medvednikov
parent 5481f226dd
commit 96152510e5
1 changed files with 3 additions and 1 deletions

View File

@ -2907,7 +2907,9 @@ fn (p mut Parser) string_expr() {
if is_array && !has_str_method { if is_array && !has_str_method {
p.gen_array_str(typ2) p.gen_array_str(typ2)
} }
args = args.all_before_last(val) + '${typ}_str(${val}).len, ${typ}_str(${val}).str' tmp_var := p.get_tmp()
p.cgen.insert_before('string $tmp_var = ${typ}_str(${val});')
args = args.all_before_last(val) + '${tmp_var}.len, ${tmp_var}.str'
format += '%.*s ' format += '%.*s '
} }
else { else {