fmt: simplify map_init

pull/5075/head
Ned Palacios 2020-05-27 21:26:45 +08:00 committed by GitHub
parent a4af4f9fe7
commit e0db880791
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 11 additions and 7 deletions

View File

@ -590,18 +590,22 @@ pub fn (mut f Fmt) expr(node ast.Expr) {
} }
ast.MapInit { ast.MapInit {
if it.keys.len == 0 { if it.keys.len == 0 {
if it.value_type == 0 { mut ktyp := it.key_type
mut vtyp := it.value_type
if vtyp == 0 {
typ_sym := f.table.get_type_symbol(it.typ) typ_sym := f.table.get_type_symbol(it.typ)
minfo := typ_sym.info as table.Map minfo := 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 ktyp = minfo.key_type
f.write('map[${mk}]${mv}{}') vtyp = minfo.value_type
return
} }
f.write('map[') f.write('map[')
f.write(f.type_to_str(it.key_type)) f.write(f.type_to_str(ktyp))
f.write(']') f.write(']')
f.write(f.type_to_str(it.value_type)) f.write(f.type_to_str(vtyp))
f.write('{}')
return return
} }
f.writeln('{') f.writeln('{')