mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
checker: fix a bug checking generic closures (#18489)
This commit is contained in:
parent
2bedb6ffd7
commit
7c1ace02f3
@ -459,12 +459,12 @@ fn (mut c Checker) anon_fn(mut node ast.AnonFn) ast.Type {
|
|||||||
}
|
}
|
||||||
node.decl.scope.update_var_type(var.name, var.typ)
|
node.decl.scope.update_var_type(var.name, var.typ)
|
||||||
}
|
}
|
||||||
c.stmts(node.decl.stmts)
|
|
||||||
c.fn_decl(mut node.decl)
|
|
||||||
if has_generic && node.decl.generic_names.len == 0 {
|
if has_generic && node.decl.generic_names.len == 0 {
|
||||||
c.error('generic closure fn must specify type parameter, e.g. fn [foo] [T]()',
|
c.error('generic closure fn must specify type parameter, e.g. fn [foo] [T]()',
|
||||||
node.decl.pos)
|
node.decl.pos)
|
||||||
}
|
}
|
||||||
|
c.stmts(node.decl.stmts)
|
||||||
|
c.fn_decl(mut node.decl)
|
||||||
return node.typ
|
return node.typ
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
vlib/v/checker/tests/generic_closure_fn_decl_err.vv:5:2: error: generic closure fn must specify type parameter, e.g. fn [foo] [T]()
|
vlib/v/checker/tests/generic_closure_fn_decl_err_a.vv:5:2: error: generic closure fn must specify type parameter, e.g. fn [foo] [T]()
|
||||||
3 |
|
3 |
|
||||||
4 | pub fn (mut app App) register[T](service T) {
|
4 | pub fn (mut app App) register[T](service T) {
|
||||||
5 | fn [service] () {
|
5 | fn [service] () {
|
7
vlib/v/checker/tests/generic_closure_fn_decl_err_b.out
Normal file
7
vlib/v/checker/tests/generic_closure_fn_decl_err_b.out
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
vlib/v/checker/tests/generic_closure_fn_decl_err_b.vv:13:2: error: generic closure fn must specify type parameter, e.g. fn [foo] [T]()
|
||||||
|
11 | println(typeof(my_plugin).name) // MyPlugin
|
||||||
|
12 |
|
||||||
|
13 | fn[my_plugin](){ my_plugin.on_update() }()
|
||||||
|
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
14 | }
|
||||||
|
15 |
|
18
vlib/v/checker/tests/generic_closure_fn_decl_err_b.vv
Normal file
18
vlib/v/checker/tests/generic_closure_fn_decl_err_b.vv
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
struct MyPlugin {
|
||||||
|
}
|
||||||
|
|
||||||
|
fn (p MyPlugin) on_update() {
|
||||||
|
println('[MyPlugin.on_update]')
|
||||||
|
}
|
||||||
|
|
||||||
|
fn foo[T](my_plugin T) {
|
||||||
|
println('[foo]')
|
||||||
|
println(T.name) // MyPlugin
|
||||||
|
println(typeof(my_plugin).name) // MyPlugin
|
||||||
|
|
||||||
|
fn[my_plugin](){ my_plugin.on_update() }()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
foo[MyPlugin](MyPlugin{})
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user