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:
parent
e3e8bb2f88
commit
f0108323d1
@ -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)
|
||||
|
17
vlib/v/tests/generics_closure_fn_direct_call_test.v
Normal file
17
vlib/v/tests/generics_closure_fn_direct_call_test.v
Normal 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
|
||||
}
|
Loading…
Reference in New Issue
Block a user