From 3e655d6bf6a530a15f6b6e53c9f6aed9d00eee16 Mon Sep 17 00:00:00 2001 From: Joe Conigliaro Date: Thu, 31 Dec 2020 10:21:02 +1100 Subject: [PATCH] cgen: fix multi return auto str methods. closes #7726 --- vlib/v/gen/auto_str_methods.v | 4 ++-- vlib/v/tests/str_gen_test.v | 36 ++++++++++++++++++++++++++++++++++- 2 files changed, 37 insertions(+), 3 deletions(-) diff --git a/vlib/v/gen/auto_str_methods.v b/vlib/v/gen/auto_str_methods.v index 1830e8402d..1d011a094c 100644 --- a/vlib/v/gen/auto_str_methods.v +++ b/vlib/v/gen/auto_str_methods.v @@ -368,13 +368,13 @@ fn (mut g Gen) gen_str_for_multi_return(info table.MultiReturn, styp string, str arg_str_fn_name = styp_to_str_fn_name(field_styp) } if sym.kind == .struct_ && !sym_has_str_method { - g.auto_str_funcs.writeln('\tstrings__Builder_write(&sb, ${str_fn_name}(a.arg$i));') + g.auto_str_funcs.writeln('\tstrings__Builder_write(&sb, ${arg_str_fn_name}(a.arg$i));') } else if sym.kind in [.f32, .f64] { g.auto_str_funcs.writeln('\tstrings__Builder_write(&sb, _STR("%g", 1, a.arg$i));') } else if sym.kind == .string { g.auto_str_funcs.writeln('\tstrings__Builder_write(&sb, _STR("\'%.*s\\000\'", 2, a.arg$i));') } else if sym.kind == .function { - g.auto_str_funcs.writeln('\tstrings__Builder_write(&sb, ${str_fn_name}());') + g.auto_str_funcs.writeln('\tstrings__Builder_write(&sb, ${arg_str_fn_name}());') } else { if (str_method_expects_ptr && is_arg_ptr) || (!str_method_expects_ptr && !is_arg_ptr) { g.auto_str_funcs.writeln('\tstrings__Builder_write(&sb, ${arg_str_fn_name}(a.arg$i));') diff --git a/vlib/v/tests/str_gen_test.v b/vlib/v/tests/str_gen_test.v index 0cba2baf57..eac0ad261a 100644 --- a/vlib/v/tests/str_gen_test.v +++ b/vlib/v/tests/str_gen_test.v @@ -357,4 +357,38 @@ fn test_struct_with_option() { w := OptionWrapperInt{} assert '$w' == 'OptionWrapperInt{\n x: Option(error: \'\')\n}' } -*/ \ No newline at end of file +*/ + +struct One { + value string = "one" +} + +struct Two { + value string = "two" +} + +fn mr_int_int() (int, int) { + return 111, 222 +} + +fn mr_one_two() (One, Two) { + one := One{} + two := Two{} + return one, two +} + +fn mr_fn_fn() (fn(int), fn(int)) { + a := fn(a int) {} + b := fn(a int) {} + return a,b +} + +fn test_multi_return() { + assert '$mr_int_int()' == '(111, 222)' + assert '$mr_fn_fn()' == '(fn (int), fn (int))' + assert '$mr_one_two()' == "(One{ + value: 'one' +}, Two{ + value: 'two' +})" +}