Skip to content

Commit b2ff9d5

Browse files
authored
ast: fix the registration of fixed arrays, when size_expr is a const (fix #23946) (#23949)
1 parent e1ce57d commit b2ff9d5

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

vlib/v/ast/table.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -991,7 +991,7 @@ pub fn (t &Table) array_fixed_name(elem_type Type, size int, size_expr Expr) str
991991
ptr := if elem_type.is_ptr() { '&'.repeat(elem_type.nr_muls()) } else { '' }
992992
opt := if elem_type.has_flag(.option) { '?' } else { '' }
993993
res := if elem_type.has_flag(.result) { '!' } else { '' }
994-
size_str := if size_expr is EmptyExpr || size != 987654321 {
994+
size_str := if size_expr is EmptyExpr || size !in [0, 987654321] {
995995
size.str()
996996
} else {
997997
size_expr.str()
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
module main
2+
3+
const c_u16_size = sizeof(u16)
4+
const c_u32_size = sizeof(u32)
5+
6+
pub enum DataKind as u8 {
7+
u8_array
8+
}
9+
10+
union U16Bytes {
11+
value u16
12+
bytes [c_u16_size]u8
13+
}
14+
15+
union U32Bytes {
16+
value u32
17+
bytes [c_u32_size]u8
18+
}
19+
20+
fn test_main() {
21+
kind := DataKind.u8_array
22+
match kind {
23+
.u8_array {
24+
buf_4u8 := [c_u32_size]u8{}
25+
w := U32Bytes{
26+
bytes: buf_4u8
27+
}
28+
unsafe {
29+
assert w.bytes.len == c_u32_size
30+
}
31+
}
32+
}
33+
}

0 commit comments

Comments
 (0)