From 875c165495b0d6b607cb943ced2b3f289903cdef Mon Sep 17 00:00:00 2001 From: Felipe Pena Date: Fri, 2 May 2025 10:39:33 -0300 Subject: [PATCH] table: fix array of scoped struct (fix #24387) (#24388) --- vlib/v/ast/table.v | 6 ++++- vlib/v/tests/structs/struct_scoped_test.v | 32 +++++++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 vlib/v/tests/structs/struct_scoped_test.v diff --git a/vlib/v/ast/table.v b/vlib/v/ast/table.v index f768b6719e..2088abaeaf 100644 --- a/vlib/v/ast/table.v +++ b/vlib/v/ast/table.v @@ -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] diff --git a/vlib/v/tests/structs/struct_scoped_test.v b/vlib/v/tests/structs/struct_scoped_test.v new file mode 100644 index 0000000000..49f6840015 --- /dev/null +++ b/vlib/v/tests/structs/struct_scoped_test.v @@ -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 + } +}