From 693e5137ebf15bc037051b5681f7924354cac852 Mon Sep 17 00:00:00 2001 From: Lukas Neubert Date: Sat, 26 Dec 2020 13:22:50 +0100 Subject: [PATCH] fmt: cleanup copy pasta for array_init (#7579) --- vlib/v/fmt/fmt.v | 28 ---------------------------- vlib/v/fmt/tests/array_init_keep.vv | 3 +++ 2 files changed, 3 insertions(+), 28 deletions(-) diff --git a/vlib/v/fmt/fmt.v b/vlib/v/fmt/fmt.v index 98b7ce38df..601e2676ef 100644 --- a/vlib/v/fmt/fmt.v +++ b/vlib/v/fmt/fmt.v @@ -1750,36 +1750,8 @@ pub fn (mut f Fmt) chan_init(mut it ast.ChanInit) { pub fn (mut f Fmt) array_init(it ast.ArrayInit) { if it.exprs.len == 0 && it.typ != 0 && it.typ != table.void_type { // `x := []string` - typ_sym := f.table.get_type_symbol(it.typ) - if typ_sym.kind == .array && typ_sym.name.starts_with('array_map') { - ainfo := typ_sym.info as table.Array - map_typ_sym := f.table.get_type_symbol(ainfo.elem_type) - minfo := map_typ_sym.info as table.Map - mk := f.table.get_type_symbol(minfo.key_type).name - mv := f.table.get_type_symbol(minfo.value_type).name - for _ in 0 .. ainfo.nr_dims { - f.write('[]') - } - f.write('map[$mk]$mv') - f.write('{') - if it.has_len { - f.write('len: ') - f.expr(it.len_expr) - } - if it.has_cap { - f.write('cap: ') - f.expr(it.cap_expr) - } - if it.has_default { - f.write('init: ') - f.expr(it.default_expr) - } - f.write('}') - return - } f.write(f.table.type_to_str_using_aliases(it.typ, f.mod2alias)) f.write('{') - // TODO copypasta if it.has_len { f.write('len: ') f.expr(it.len_expr) diff --git a/vlib/v/fmt/tests/array_init_keep.vv b/vlib/v/fmt/tests/array_init_keep.vv index 93518b1b48..346d5d2b11 100644 --- a/vlib/v/fmt/tests/array_init_keep.vv +++ b/vlib/v/fmt/tests/array_init_keep.vv @@ -15,4 +15,7 @@ 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]} }