vfmt: fix deep nested map types, using f.table.type_to_str

pull/6613/head
Delyan Angelov 2020-10-13 16:06:40 +03:00
parent 78bcda14c4
commit 1123f4fcc9
2 changed files with 7 additions and 13 deletions

View File

@ -590,7 +590,7 @@ pub fn (mut f Fmt) struct_decl(node ast.StructDecl) {
if comments_len + field.name.len > max { if comments_len + field.name.len > max {
max = comments_len + field.name.len max = comments_len + field.name.len
} }
ft := f.type_to_str(field.typ) ft := f.table.type_to_str(field.typ)
field_types << ft field_types << ft
if ft.len > max_type { if ft.len > max_type {
max_type = ft.len max_type = ft.len
@ -886,18 +886,7 @@ pub fn (mut f Fmt) expr(node ast.Expr) {
} }
ast.MapInit { ast.MapInit {
if node.keys.len == 0 { if node.keys.len == 0 {
mut ktyp := node.key_type f.write(f.table.type_to_str(node.typ))
mut vtyp := node.value_type
if vtyp == 0 {
typ_sym := f.table.get_type_symbol(node.typ)
minfo := typ_sym.info as table.Map
ktyp = minfo.key_type
vtyp = minfo.value_type
}
f.write('map[')
f.write(f.type_to_str(ktyp))
f.write(']')
f.write(f.type_to_str(vtyp))
f.write('{}') f.write('{}')
return return
} }

View File

@ -20,6 +20,10 @@ struct Abcde {
p4 []&Xyz p4 []&Xyz
p5 map[string]Xyz p5 map[string]Xyz
p6 map[string]&Xyz p6 map[string]&Xyz
p7 map[string]map[string]map[string]&Xyz
//
p8 map[string]map[string]map[string]map[string]&Xyz
p9 map[string]map[string]map[string]map[string]&vproto.Xyz
} }
fn abc() { fn abc() {
@ -27,4 +31,5 @@ fn abc() {
mut a := []vproto.Xyz{} mut a := []vproto.Xyz{}
a << x a << x
a << vproto.Xyz{3} a << vproto.Xyz{3}
z := map[string]map[string]map[string]map[string]&vproto.Xyz{}
} }