cgen: fix multi return auto str methods. closes #7726

pull/7735/head^2
Joe Conigliaro 2020-12-31 10:21:02 +11:00
parent 9a31744255
commit 3e655d6bf6
No known key found for this signature in database
GPG Key ID: C12F7136C08206F1
2 changed files with 37 additions and 3 deletions

View File

@ -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));')

View File

@ -357,4 +357,38 @@ fn test_struct_with_option() {
w := OptionWrapperInt{}
assert '$w' == 'OptionWrapperInt{\n x: Option(error: \'\')\n}'
}
*/
*/
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'
})"
}