Skip to content

Commit 9fcca59

Browse files
authored
cgen: fix codegen for generic struct field array option (fix #25093) (#25097)
1 parent e5100a8 commit 9fcca59

2 files changed

Lines changed: 41 additions & 2 deletions

File tree

‎vlib/v/gen/c/cgen.v‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5444,7 +5444,7 @@ fn (mut g Gen) ident(node ast.Ident) {
54445444
}
54455445
if i == 0 && node.obj.ct_type_var != .smartcast && node.obj.is_unwrapped {
54465446
dot := if (!node.obj.ct_type_unwrapped && !node.obj.orig_type.is_ptr()
5447-
&& obj_sym.is_heap())
5447+
&& !node.obj.orig_type.has_flag(.generic) && obj_sym.is_heap())
54485448
|| node.obj.orig_type.has_flag(.option_mut_param_t) {
54495449
'->'
54505450
} else {
@@ -6727,7 +6727,7 @@ fn (mut g Gen) write_types(symbols []&ast.TypeSymbol) {
67276727
for opt_field in opt_fields {
67286728
field_sym := g.table.final_sym(opt_field.typ)
67296729
arr := field_sym.info as ast.ArrayFixed
6730-
if !arr.elem_type.has_flag(.option) {
6730+
if !arr.elem_type.has_flag(.option) || arr.elem_type.has_flag(.generic) {
67316731
continue
67326732
}
67336733
styp := field_sym.cname
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
module main
2+
3+
@[heap]
4+
struct FLQueue[T] {
5+
mut:
6+
inner [8]?T
7+
}
8+
9+
fn (mut f FLQueue[T]) put[T](element T) {
10+
for index, item in f.inner {
11+
if item == none {
12+
f.inner[index] = element
13+
return
14+
}
15+
}
16+
panic('put: No free slot')
17+
}
18+
19+
fn (mut f FLQueue[T]) get[T]() ?T {
20+
for item in f.inner {
21+
if item != none {
22+
return item
23+
}
24+
}
25+
return none
26+
}
27+
28+
@[heap]
29+
struct Thread {
30+
stack [1024]u8
31+
}
32+
33+
fn test_main() {
34+
mut q := FLQueue[Thread]{}
35+
t := Thread{}
36+
q.put(t)
37+
p := q.get()
38+
println(p)
39+
}

0 commit comments

Comments
 (0)