table: fix array of scoped struct (fix #24387) (#24388)

This commit is contained in:
Felipe Pena 2025-05-02 10:39:33 -03:00 committed by GitHub
parent ac7512b2c2
commit 875c165495
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 37 additions and 1 deletions

View File

@ -966,7 +966,11 @@ pub fn (t &Table) array_name(elem_type Type) string {
ptr := if elem_type.is_ptr() { '&'.repeat(elem_type.nr_muls()) } else { '' }
opt := if elem_type.has_flag(.option) { '?' } else { '' }
res := if elem_type.has_flag(.result) { '!' } else { '' }
return '[]${opt}${res}${ptr}${elem_type_sym.name}'
mut name := elem_type_sym.name
if elem_type_sym.info is Struct && elem_type_sym.info.scoped_name != '' {
name = elem_type_sym.info.scoped_name
}
return '[]${opt}${res}${ptr}${name}'
}
@[inline]

View File

@ -0,0 +1,32 @@
module main
fn test_a() {
struct Ak {
a int
b int
}
cases := [
Ak{1, 1},
Ak{2, 2},
]
for _, k in cases {
assert k.a == k.b
}
}
fn test_b() {
struct Ak {
a int
b int
c int
}
cases := [
Ak{1, 2, 2},
Ak{2, 2, 2},
]
for _, k in cases {
assert k.b == k.c
}
}