From ddcb5f7da3c1170c0f453f6a7b99ae611f9fdee3 Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Sun, 24 May 2020 14:59:52 +0300 Subject: [PATCH] gen: fix autogenerated print methods for vargs --- vlib/v/gen/cgen.v | 11 +++-- .../vargs_auto_str_method_and_println_test.v | 44 +++++++++++++++++++ 2 files changed, 52 insertions(+), 3 deletions(-) create mode 100644 vlib/v/tests/vargs_auto_str_method_and_println_test.v diff --git a/vlib/v/gen/cgen.v b/vlib/v/gen/cgen.v index d66eb42ac5..de33747cbc 100644 --- a/vlib/v/gen/cgen.v +++ b/vlib/v/gen/cgen.v @@ -3486,7 +3486,7 @@ fn (mut g Gen) gen_str_for_type_with_styp(typ table.Type, styp string) string { if typ.flag_is(.variadic) { varg_already_generated_key := 'varg_$already_generated_key' if varg_already_generated_key !in g.str_types { - g.gen_str_for_varg(styp, str_fn_name) + g.gen_str_for_varg(styp, str_fn_name, sym_has_str_method) g.str_types << varg_already_generated_key } return 'varg_$str_fn_name' @@ -3762,13 +3762,18 @@ fn (mut g Gen) gen_str_for_map(info table.Map, styp, str_fn_name string) { g.auto_str_funcs.writeln('}') } -fn (mut g Gen) gen_str_for_varg(styp, str_fn_name string) { +fn (mut g Gen) gen_str_for_varg(styp, str_fn_name string, has_str_method bool) { g.definitions.writeln('string varg_${str_fn_name}(varg_$styp it); // auto') g.auto_str_funcs.writeln('string varg_${str_fn_name}(varg_$styp it) {') g.auto_str_funcs.writeln('\tstrings__Builder sb = strings__new_builder(it.len);') g.auto_str_funcs.writeln('\tstrings__Builder_write(&sb, tos_lit("["));') g.auto_str_funcs.writeln('\tfor(int i=0; i