cgen: fix callback codegen on generic struct resolution (fix #24947) (#24948)

This commit is contained in:
Felipe Pena 2025-07-23 14:49:25 -03:00 committed by GitHub
parent 7472a745e0
commit edf6c22e9c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 40 additions and 0 deletions

View File

@ -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(

View 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
}