diff --git a/vlib/v/ast/table.v b/vlib/v/ast/table.v index 2807e3fa7b3d8e..dc2dec7d7e4b2e 100644 --- a/vlib/v/ast/table.v +++ b/vlib/v/ast/table.v @@ -991,7 +991,7 @@ pub fn (t &Table) array_fixed_name(elem_type Type, size int, size_expr Expr) str 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 { '' } - size_str := if size_expr is EmptyExpr || size != 987654321 { + size_str := if size_expr is EmptyExpr || size !in [0, 987654321] { size.str() } else { size_expr.str() diff --git a/vlib/v/tests/consts/const_fixed_array_test.v b/vlib/v/tests/consts/const_fixed_array_test.v new file mode 100644 index 00000000000000..33e74ad5f8af1f --- /dev/null +++ b/vlib/v/tests/consts/const_fixed_array_test.v @@ -0,0 +1,33 @@ +module main + +const c_u16_size = sizeof(u16) +const c_u32_size = sizeof(u32) + +pub enum DataKind as u8 { + u8_array +} + +union U16Bytes { + value u16 + bytes [c_u16_size]u8 +} + +union U32Bytes { + value u32 + bytes [c_u32_size]u8 +} + +fn test_main() { + kind := DataKind.u8_array + match kind { + .u8_array { + buf_4u8 := [c_u32_size]u8{} + w := U32Bytes{ + bytes: buf_4u8 + } + unsafe { + assert w.bytes.len == c_u32_size + } + } + } +}