diff --git a/vlib/v/checker/containers.v b/vlib/v/checker/containers.v index 596d28ee45646d..b94dd7a0232e30 100644 --- a/vlib/v/checker/containers.v +++ b/vlib/v/checker/containers.v @@ -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) { diff --git a/vlib/v/tests/enums/enum_array_init_test.v b/vlib/v/tests/enums/enum_array_init_test.v new file mode 100644 index 00000000000000..4b67d02564cbaa --- /dev/null +++ b/vlib/v/tests/enums/enum_array_init_test.v @@ -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) +}