diff --git a/vlib/builtin/array_test.v b/vlib/builtin/array_test.v index c4d7f4865f..7762af060a 100644 --- a/vlib/builtin/array_test.v +++ b/vlib/builtin/array_test.v @@ -1337,3 +1337,9 @@ fn test_array_of_multi_map() { assert nums.odds == [3, 5, 7] assert nums.evens == [2, 6, 10] } + +fn test_multi_fixed_array_with_default_init() { + a := [3][3]int{init: [3]int{init: 10}} + println(a) + assert a == [[10, 10, 10]!, [10, 10, 10]!, [10, 10, 10]!]! +} diff --git a/vlib/v/checker/checker.v b/vlib/v/checker/checker.v index 7fd8130cb2..fd7957299f 100644 --- a/vlib/v/checker/checker.v +++ b/vlib/v/checker/checker.v @@ -2768,6 +2768,9 @@ pub fn (mut c Checker) array_init(mut array_init ast.ArrayInit) table.Type { 1) array_type := table.new_type(idx) array_init.typ = array_type + if array_init.has_default { + c.expr(array_init.default_expr) + } } return array_init.typ } diff --git a/vlib/v/gen/array.v b/vlib/v/gen/array.v index 584502415a..6a396e851b 100644 --- a/vlib/v/gen/array.v +++ b/vlib/v/gen/array.v @@ -35,6 +35,13 @@ fn (mut g Gen) array_init(it ast.ArrayInit) { g.write(', ') } } + } else if it.has_default { + g.expr(it.default_expr) + info := type_sym.info as table.ArrayFixed + for _ in 1 .. info.size { + g.write(', ') + g.expr(it.default_expr) + } } else { g.write('0') }