diff --git a/vlib/v/fmt/fmt.v b/vlib/v/fmt/fmt.v index 601e2676ef..9ea485d9de 100644 --- a/vlib/v/fmt/fmt.v +++ b/vlib/v/fmt/fmt.v @@ -1840,7 +1840,9 @@ pub fn (mut f Fmt) array_init(it ast.ArrayInit) { } f.write(f.table.type_to_str(it.elem_type)) if it.has_default { - f.write('{init: $it.default_expr}') + f.write('{init: ') + f.expr(it.default_expr) + f.write('}') } else { f.write('{}') } diff --git a/vlib/v/fmt/tests/array_init_keep.vv b/vlib/v/fmt/tests/array_init_keep.vv index 346d5d2b11..118fa04287 100644 --- a/vlib/v/fmt/tests/array_init_keep.vv +++ b/vlib/v/fmt/tests/array_init_keep.vv @@ -16,6 +16,10 @@ fn main() { 'eggs', ] _ := []int{len: 10, cap: 10, init: 7} - _ := []map[string]string{len: 5, cap: 50, init: 'a'} - _ := []map[string][]int{len: 7, cap: 100, init: [1, 2]} + _ := []map[string]string{len: 5, cap: 50, init: { + 'a': 'a' + }} + _ := []map[string][]int{len: 7, cap: 100, init: { + 'a': [1, 2] + }} } diff --git a/vlib/v/fmt/tests/fixed_size_array_type_keep.vv b/vlib/v/fmt/tests/fixed_size_array_type_keep.vv index db8b16c176..435b6be9ef 100644 --- a/vlib/v/fmt/tests/fixed_size_array_type_keep.vv +++ b/vlib/v/fmt/tests/fixed_size_array_type_keep.vv @@ -1,3 +1,7 @@ fn foo() [1]f32 { return [f32(0.0)]!! } + +fn main() { + _ := [5]string{init: 'abc'} +}