Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

table: fix array fixed symbol registering when size_expr is a const #23949

Merged
merged 1 commit into from
Mar 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion vlib/v/ast/table.v
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
33 changes: 33 additions & 0 deletions vlib/v/tests/consts/const_fixed_array_test.v
Original file line number Diff line number Diff line change
@@ -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
}
}
}
}
Loading