Skip to content

Commit 66caf94

Browse files
authored
checker: allow int alias to be used as array len and cap (fix #23266) (#23272)
1 parent 80bae08 commit 66caf94

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

vlib/v/checker/containers.v

+1-1
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ fn (mut c Checker) check_array_init_default_expr(mut node ast.ArrayInit) {
312312
}
313313

314314
fn (mut c Checker) check_array_init_para_type(para string, mut expr ast.Expr, pos token.Pos) {
315-
sym := c.table.sym(c.unwrap_generic(c.expr(mut expr)))
315+
sym := c.table.final_sym(c.unwrap_generic(c.expr(mut expr)))
316316
if sym.kind !in [.int, .int_literal] {
317317
c.error('array ${para} needs to be an int', pos)
318318
}
+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
type Test = int
2+
3+
fn test_array_len_int_alias() {
4+
x := Test(12)
5+
arr := []int{len: x}
6+
assert arr.len == 12
7+
}

0 commit comments

Comments
 (0)