diff --git a/vlib/v/checker/fn.v b/vlib/v/checker/fn.v index 839c03a7a7..2e68bf346e 100644 --- a/vlib/v/checker/fn.v +++ b/vlib/v/checker/fn.v @@ -855,6 +855,7 @@ pub fn (mut c Checker) fn_call(mut node ast.CallExpr, mut continue_check &bool) c.fail_if_unreadable(arg.expr, arg.typ, 'argument to print') c.inside_println_arg = false node.return_type = ast.void_type + c.set_node_expected_arg_types(mut node, func) /* // TODO: optimize `struct T{} fn (t &T) str() string {return 'abc'} mut a := []&T{} a << &T{} println(a[0])` // It currently generates: diff --git a/vlib/v/gen/c/fn.v b/vlib/v/gen/c/fn.v index e2e179df27..28bc6b3c00 100644 --- a/vlib/v/gen/c/fn.v +++ b/vlib/v/gen/c/fn.v @@ -2057,6 +2057,19 @@ fn (mut g Gen) go_expr(node ast.GoExpr) { } call_args_str = call_args_str.replace_each(rep_group) g.gowrappers.write_string(call_args_str) + } else if expr.name in ['print', 'println', 'eprint', 'eprintln', 'panic'] + && expr.args[0].typ != ast.string_type { + pos := g.out.len + g.gen_expr_to_string(expr.args[0].expr, expr.args[0].typ) + mut call_args_str := g.out.after(pos) + g.out.go_back(call_args_str.len) + mut rep_group := []string{cap: 2 * expr.args.len} + for i in 0 .. expr.args.len { + rep_group << g.expr_string(expr.args[i].expr) + rep_group << 'arg->arg${i + 1}' + } + call_args_str = call_args_str.replace_each(rep_group) + g.gowrappers.write_string(call_args_str) } else { for i in 0 .. expr.args.len { expected_nr_muls := expr.expected_arg_types[i].nr_muls() diff --git a/vlib/v/tests/inout/go_print.out b/vlib/v/tests/inout/go_print.out new file mode 100644 index 0000000000..b5d8bb58d9 --- /dev/null +++ b/vlib/v/tests/inout/go_print.out @@ -0,0 +1 @@ +[1, 2, 3] diff --git a/vlib/v/tests/inout/go_print.vv b/vlib/v/tests/inout/go_print.vv new file mode 100644 index 0000000000..78e26f662c --- /dev/null +++ b/vlib/v/tests/inout/go_print.vv @@ -0,0 +1,4 @@ +fn main(){ + g := go print([1, 2, 3]) + g.wait() +}