Skip to content

Commit edf6c22

Browse files
authored
cgen: fix callback codegen on generic struct resolution (fix #24947) (#24948)
1 parent 7472a74 commit edf6c22

2 files changed

Lines changed: 40 additions & 0 deletions

File tree

‎vlib/v/ast/table.v‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1318,6 +1318,9 @@ pub fn (mut t Table) find_or_register_fn_type(f Fn, is_anon bool, has_decl bool)
13181318
anon := f.name == '' || is_anon
13191319
existing_idx := t.type_idxs[name]
13201320
if existing_idx > 0 && t.type_symbols[existing_idx].kind != .placeholder {
1321+
if t.type_symbols[existing_idx].info is FnType && !has_decl {
1322+
t.type_symbols[existing_idx].info.has_decl = has_decl
1323+
}
13211324
return existing_idx
13221325
}
13231326
return t.register_sym(
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
pub struct ChunksArrayDecoder[T] {
2+
callback fn (t T) = unsafe { nil }
3+
}
4+
5+
pub fn new_chunks_array_decoder[T](callback fn (t T)) &ChunksArrayDecoder[T] {
6+
return &ChunksArrayDecoder[T]{
7+
callback: callback
8+
}
9+
}
10+
11+
struct Person {
12+
name string
13+
age int
14+
kgs f32
15+
}
16+
17+
@[heap]
18+
struct People {
19+
mut:
20+
persons int
21+
kgs f32
22+
}
23+
24+
fn (mut people People) callback(person Person) {
25+
people.persons++
26+
people.kgs += person.kgs
27+
}
28+
29+
fn module_callback(person Person) {
30+
println('person: ${person}')
31+
}
32+
33+
fn test_main() {
34+
mut people := &People{}
35+
mut decoder := new_chunks_array_decoder[Person](people.callback)
36+
_ = decoder
37+
}

0 commit comments

Comments
 (0)