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

cgen: fix generic closure fn direct call (#16057)

This commit is contained in:
yuyi 2022-10-13 23:06:34 +08:00 committed by GitHub
parent e3e8bb2f88
commit f0108323d1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 1 deletions

View File

@ -635,7 +635,17 @@ fn (mut g Gen) call_expr(node ast.CallExpr) {
// NOTE: everything could be done this way
// see my comment in parser near anon_fn
if node.left is ast.AnonFn {
g.expr(node.left)
if node.left.inherited_vars.len > 0 {
tmp_var := g.new_tmp_var()
fn_type := g.fn_var_signature(node.left.decl.return_type, node.left.decl.params.map(it.typ),
tmp_var)
g.write('$fn_type = ')
g.expr(node.left)
g.writeln(';')
g.write(tmp_var)
} else {
g.expr(node.left)
}
} else if node.left is ast.IndexExpr && node.name == '' {
g.is_fn_index_call = true
g.expr(node.left)

View File

@ -0,0 +1,17 @@
pub struct App {
}
pub fn (mut app App) register<T>(service T) {
fn [service] <T>() {
println(service)
}()
}
pub struct Service {
}
fn test_generics_closure_fn_direct_call() {
mut app := App{}
app.register(Service{})
assert true
}