From 90cef28dfa69668bc12303961676554326e9ba66 Mon Sep 17 00:00:00 2001 From: Swastik Baranwal Date: Mon, 16 Dec 2024 00:37:59 +0530 Subject: [PATCH] checker: allow `[]Enum{len: 10, init: .thing}` (fix #23077) (#23165) --- vlib/v/checker/containers.v | 1 + vlib/v/tests/enums/enum_array_init_test.v | 9 +++++++++ 2 files changed, 10 insertions(+) create mode 100644 vlib/v/tests/enums/enum_array_init_test.v diff --git a/vlib/v/checker/containers.v b/vlib/v/checker/containers.v index 596d28ee4..b94dd7a02 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 000000000..4b67d0256 --- /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) +} -- 2.39.5