From 92aba98b057a240b41dfe8f3a77c699addcf505d Mon Sep 17 00:00:00 2001 From: Krchi <997054144@qq.com> Date: Mon, 12 Jan 2026 15:27:26 +0800 Subject: [PATCH] cgen: fix fixed array of option with different size (#26326) --- vlib/v/gen/c/cgen.v | 2 ++ .../builtin_arrays/fixed_array_of_option_multi_size_test.v | 6 ++++++ 2 files changed, 8 insertions(+) create mode 100644 vlib/v/tests/builtin_arrays/fixed_array_of_option_multi_size_test.v diff --git a/vlib/v/gen/c/cgen.v b/vlib/v/gen/c/cgen.v index d02a8b7b0..12e568a08 100644 --- a/vlib/v/gen/c/cgen.v +++ b/vlib/v/gen/c/cgen.v @@ -1787,6 +1787,8 @@ pub fn (mut g Gen) write_typedef_types() { g.typedefs.writeln('typedef struct ${styp_elem} ${styp_elem};') g.type_definitions.writeln('${g.option_type_text(styp_elem, elem_base)};') + } + if styp !in g.done_options { g.type_definitions.writeln('typedef ${fixed} ${styp} [${len}];') g.done_options << styp } diff --git a/vlib/v/tests/builtin_arrays/fixed_array_of_option_multi_size_test.v b/vlib/v/tests/builtin_arrays/fixed_array_of_option_multi_size_test.v new file mode 100644 index 000000000..94135f3d4 --- /dev/null +++ b/vlib/v/tests/builtin_arrays/fixed_array_of_option_multi_size_test.v @@ -0,0 +1,6 @@ +fn test_main() { + a := [?int(1), 0, 2]! + b := [?int(none), none]! + assert '${a}' == '${[?int(1), 0, 2]!}' + assert '${b}' == '${[?int(none), none]!}' +} -- 2.39.5