1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

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

This commit is contained in:
yuyi 2022-04-28 19:43:20 +08:00 committed by GitHub
parent c802688690
commit dd94ab890a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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)
} 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(', ')

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