From 96152510e52c75e70b4be3100ed2a6a698e4917e Mon Sep 17 00:00:00 2001 From: Vinicius Rangel Date: Thu, 17 Oct 2019 01:02:02 -0300 Subject: [PATCH] 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 --- vlib/compiler/parser.v | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/vlib/compiler/parser.v b/vlib/compiler/parser.v index 3a8fbd5cff..54bfd13e42 100644 --- a/vlib/compiler/parser.v +++ b/vlib/compiler/parser.v @@ -2907,7 +2907,9 @@ fn (p mut Parser) string_expr() { if is_array && !has_str_method { 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 ' } else {