From 9a5bbc310166bb070cf44791698c55a1632488aa Mon Sep 17 00:00:00 2001 From: Lukas Neubert Date: Sat, 26 Dec 2020 14:12:25 +0100 Subject: [PATCH] fmt: use single quotes around fixed string arr default expr (#7581) --- vlib/v/fmt/fmt.v | 4 +++- vlib/v/fmt/tests/array_init_keep.vv | 8 ++++++-- vlib/v/fmt/tests/fixed_size_array_type_keep.vv | 4 ++++ 3 files changed, 13 insertions(+), 3 deletions(-) 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'} +}