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

cgen: fix go call fn with anon fn argument (fix #10351, fix #10270) (#15446)

This commit is contained in:
yuyi 2022-08-17 21:12:52 +08:00 committed by GitHub
parent 70f466460f
commit 9887dd1fbf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 2 deletions

View File

@ -1826,8 +1826,15 @@ fn (mut g Gen) go_expr(node ast.GoExpr) {
g.type_definitions.writeln('EMPTY_STRUCT_DECLARATION;')
} else {
for i, arg in expr.args {
styp := g.typ(arg.typ)
g.type_definitions.writeln('\t$styp arg${i + 1};')
arg_sym := g.table.sym(arg.typ)
if arg_sym.info is ast.FnType {
sig := g.fn_var_signature(arg_sym.info.func.return_type, arg_sym.info.func.params,
'arg${i + 1}')
g.type_definitions.writeln('\t' + sig + ';')
} else {
styp := g.typ(arg.typ)
g.type_definitions.writeln('\t$styp arg${i + 1};')
}
}
}
if need_return_ptr {

View File

@ -0,0 +1,14 @@
fn start(f fn ()) string {
f()
return 'ok!!'
}
fn on_connect() {
println('fn ok!!')
}
fn test_go_call_fn_with_anon_fn_arg() {
g := go start(on_connect)
ret := g.wait()
assert ret == 'ok!!'
}