cgen: fix go anon fn call with ref argument (fix #14192) (#14197)

yuyi 2022-04-28 19:43:20 +08:00 committed by Jef Roosens
parent 03d2258b6d
commit c2ecfb32d9
Signed by: Jef Roosens
GPG Key ID: B75D4F293C7052DB
2 changed files with 22 additions and 0 deletions

View File

@ -1922,6 +1922,13 @@ fn (mut g Gen) go_expr(node ast.GoExpr) {
g.gowrappers.write_string(call_args_str) g.gowrappers.write_string(call_args_str)
} else { } else {
for i in 0 .. expr.args.len { 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}') g.gowrappers.write_string('arg->arg${i + 1}')
if i != expr.args.len - 1 { if i != expr.args.len - 1 {
g.gowrappers.write_string(', ') g.gowrappers.write_string(', ')

View File

@ -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'
}