Skip to content

Commit

Permalink
checker: allow int alias to be used as array len and cap (fix #23266
Browse files Browse the repository at this point in the history
) (#23272)
  • Loading branch information
Delta456 authored Dec 26, 2024
1 parent 80bae08 commit 66caf94
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion vlib/v/checker/containers.v
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ fn (mut c Checker) check_array_init_default_expr(mut node ast.ArrayInit) {
}

fn (mut c Checker) check_array_init_para_type(para string, mut expr ast.Expr, pos token.Pos) {
sym := c.table.sym(c.unwrap_generic(c.expr(mut expr)))
sym := c.table.final_sym(c.unwrap_generic(c.expr(mut expr)))
if sym.kind !in [.int, .int_literal] {
c.error('array ${para} needs to be an int', pos)
}
Expand Down
7 changes: 7 additions & 0 deletions vlib/v/tests/array_len_int_alias_test.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
type Test = int

fn test_array_len_int_alias() {
x := Test(12)
arr := []int{len: x}
assert arr.len == 12
}

0 comments on commit 66caf94

Please sign in to comment.