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

checker: allow int alias to be used as array len and cap #23272

Merged
merged 3 commits into from
Dec 26, 2024
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/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
}
Loading