Skip to content

Commit

Permalink
checker: allow []Enum{len: 10, init: .thing}
Browse files Browse the repository at this point in the history
  • Loading branch information
Delta456 authored and spytheman committed Dec 15, 2024
1 parent 44db4d5 commit 071f751
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
1 change: 1 addition & 0 deletions vlib/v/checker/containers.v
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ fn (mut c Checker) array_init(mut node ast.ArrayInit) ast.Type {

fn (mut c Checker) check_array_init_default_expr(mut node ast.ArrayInit) {
mut init_expr := node.init_expr
c.expected_type = node.elem_type
init_typ := c.check_expr_option_or_result_call(init_expr, c.expr(mut init_expr))
node.init_type = init_typ
if !node.elem_type.has_flag(.option) && init_typ.has_flag(.option) {
Expand Down
9 changes: 9 additions & 0 deletions vlib/v/tests/enums/enum_array_init_test.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
enum Enum {
thing = 10
}

fn test_enum_array_init() {
x := []Enum{len: 10, init: .thing}
assert x[0] == .thing
assert x.all(it == .thing)
}

0 comments on commit 071f751

Please sign in to comment.