Skip to content

Commit dd94ab8

Browse files
authored
cgen: fix go anon fn call with ref argument (fix #14192) (#14197)
1 parent c802688 commit dd94ab8

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

vlib/v/gen/c/fn.v

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1922,6 +1922,13 @@ fn (mut g Gen) go_expr(node ast.GoExpr) {
19221922
g.gowrappers.write_string(call_args_str)
19231923
} else {
19241924
for i in 0 .. expr.args.len {
1925+
expected_nr_muls := expr.expected_arg_types[i].nr_muls()
1926+
arg_nr_muls := expr.args[i].typ.nr_muls()
1927+
if arg_nr_muls > expected_nr_muls {
1928+
g.gowrappers.write_string('*'.repeat(arg_nr_muls - expected_nr_muls))
1929+
} else if arg_nr_muls < expected_nr_muls {
1930+
g.gowrappers.write_string('&'.repeat(expected_nr_muls - arg_nr_muls))
1931+
}
19251932
g.gowrappers.write_string('arg->arg${i + 1}')
19261933
if i != expr.args.len - 1 {
19271934
g.gowrappers.write_string(', ')
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
struct Foo {
2+
bar string
3+
}
4+
5+
fn test_go_anon_fn_call_with_ref_arg() {
6+
foo := &Foo{
7+
bar: 'hello'
8+
}
9+
g := go fn (foo Foo) string {
10+
return foo.bar
11+
}(foo)
12+
ret := g.wait()
13+
println(ret)
14+
assert ret == 'hello'
15+
}

0 commit comments

Comments
 (0)