diff --git a/vlib/v/gen/c/fn.v b/vlib/v/gen/c/fn.v index 5bd571cc8b..5944d7fc77 100644 --- a/vlib/v/gen/c/fn.v +++ b/vlib/v/gen/c/fn.v @@ -1922,6 +1922,13 @@ fn (mut g Gen) go_expr(node ast.GoExpr) { 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() + arg_nr_muls := expr.args[i].typ.nr_muls() + if arg_nr_muls > expected_nr_muls { + g.gowrappers.write_string('*'.repeat(arg_nr_muls - expected_nr_muls)) + } else if arg_nr_muls < expected_nr_muls { + g.gowrappers.write_string('&'.repeat(expected_nr_muls - arg_nr_muls)) + } g.gowrappers.write_string('arg->arg${i + 1}') if i != expr.args.len - 1 { g.gowrappers.write_string(', ') diff --git a/vlib/v/tests/go_anon_fn_call_with_ref_arg_test.v b/vlib/v/tests/go_anon_fn_call_with_ref_arg_test.v new file mode 100644 index 0000000000..4caf394279 --- /dev/null +++ b/vlib/v/tests/go_anon_fn_call_with_ref_arg_test.v @@ -0,0 +1,15 @@ +struct Foo { + bar string +} + +fn test_go_anon_fn_call_with_ref_arg() { + foo := &Foo{ + bar: 'hello' + } + g := go fn (foo Foo) string { + return foo.bar + }(foo) + ret := g.wait() + println(ret) + assert ret == 'hello' +}