mirror of
https://github.com/vlang/v.git
synced 2025-08-03 17:57:59 -04:00
This commit is contained in:
parent
7472a745e0
commit
edf6c22e9c
@ -1318,6 +1318,9 @@ pub fn (mut t Table) find_or_register_fn_type(f Fn, is_anon bool, has_decl bool)
|
||||
anon := f.name == '' || is_anon
|
||||
existing_idx := t.type_idxs[name]
|
||||
if existing_idx > 0 && t.type_symbols[existing_idx].kind != .placeholder {
|
||||
if t.type_symbols[existing_idx].info is FnType && !has_decl {
|
||||
t.type_symbols[existing_idx].info.has_decl = has_decl
|
||||
}
|
||||
return existing_idx
|
||||
}
|
||||
return t.register_sym(
|
||||
|
37
vlib/v/tests/structs/struct_anon_generic_fn_field_test.v
Normal file
37
vlib/v/tests/structs/struct_anon_generic_fn_field_test.v
Normal file
@ -0,0 +1,37 @@
|
||||
pub struct ChunksArrayDecoder[T] {
|
||||
callback fn (t T) = unsafe { nil }
|
||||
}
|
||||
|
||||
pub fn new_chunks_array_decoder[T](callback fn (t T)) &ChunksArrayDecoder[T] {
|
||||
return &ChunksArrayDecoder[T]{
|
||||
callback: callback
|
||||
}
|
||||
}
|
||||
|
||||
struct Person {
|
||||
name string
|
||||
age int
|
||||
kgs f32
|
||||
}
|
||||
|
||||
@[heap]
|
||||
struct People {
|
||||
mut:
|
||||
persons int
|
||||
kgs f32
|
||||
}
|
||||
|
||||
fn (mut people People) callback(person Person) {
|
||||
people.persons++
|
||||
people.kgs += person.kgs
|
||||
}
|
||||
|
||||
fn module_callback(person Person) {
|
||||
println('person: ${person}')
|
||||
}
|
||||
|
||||
fn test_main() {
|
||||
mut people := &People{}
|
||||
mut decoder := new_chunks_array_decoder[Person](people.callback)
|
||||
_ = decoder
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user