cgen: fix codegen for generic struct field array option (fix #25093) (#25097)

This commit is contained in:
Felipe Pena 2025-08-13 03:11:01 -03:00 committed by GitHub
parent e5100a8f73
commit 9fcca599a5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 41 additions and 2 deletions

View file

@ -5444,7 +5444,7 @@ fn (mut g Gen) ident(node ast.Ident) {
}
if i == 0 && node.obj.ct_type_var != .smartcast && node.obj.is_unwrapped {
dot := if (!node.obj.ct_type_unwrapped && !node.obj.orig_type.is_ptr()
&& obj_sym.is_heap())
&& !node.obj.orig_type.has_flag(.generic) && obj_sym.is_heap())
|| node.obj.orig_type.has_flag(.option_mut_param_t) {
'->'
} else {
@ -6727,7 +6727,7 @@ fn (mut g Gen) write_types(symbols []&ast.TypeSymbol) {
for opt_field in opt_fields {
field_sym := g.table.final_sym(opt_field.typ)
arr := field_sym.info as ast.ArrayFixed
if !arr.elem_type.has_flag(.option) {
if !arr.elem_type.has_flag(.option) || arr.elem_type.has_flag(.generic) {
continue
}
styp := field_sym.cname

View file

@ -0,0 +1,39 @@
module main
@[heap]
struct FLQueue[T] {
mut:
inner [8]?T
}
fn (mut f FLQueue[T]) put[T](element T) {
for index, item in f.inner {
if item == none {
f.inner[index] = element
return
}
}
panic('put: No free slot')
}
fn (mut f FLQueue[T]) get[T]() ?T {
for item in f.inner {
if item != none {
return item
}
}
return none
}
@[heap]
struct Thread {
stack [1024]u8
}
fn test_main() {
mut q := FLQueue[Thread]{}
t := Thread{}
q.put(t)
p := q.get()
println(p)
}