fmt: cleanup copy pasta for array_init (#7579)

pull/7581/head
Lukas Neubert 2020-12-26 13:22:50 +01:00 committed by GitHub
parent f707e13b3f
commit 693e5137eb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 28 deletions

View File

@ -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)

View File

@ -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]}
}