diff --git a/vlib/v/fmt/fmt.v b/vlib/v/fmt/fmt.v index 37a5b4bb64..44246970c0 100644 --- a/vlib/v/fmt/fmt.v +++ b/vlib/v/fmt/fmt.v @@ -245,6 +245,12 @@ pub fn (mut f Fmt) short_module(name string) string { pub fn (mut f Fmt) mark_types_import_as_used(typ ast.Type) { sym := f.table.get_type_symbol(typ) + if sym.info is ast.Map { + map_info := sym.map_info() + f.mark_types_import_as_used(map_info.key_type) + f.mark_types_import_as_used(map_info.value_type) + return + } name := sym.name.split('<')[0] // take `Type` from `Type` f.mark_import_as_used(name) } diff --git a/vlib/v/fmt/tests/import_selective_expected.vv b/vlib/v/fmt/tests/import_selective_expected.vv index 66e4621ff6..8e21735f66 100644 --- a/vlib/v/fmt/tests/import_selective_expected.vv +++ b/vlib/v/fmt/tests/import_selective_expected.vv @@ -18,6 +18,8 @@ import mod { RightOfIs, StructEmbed, StructField, + StructMapFieldKey, + StructMapFieldValue, StructMethodArg, StructMethodArgGeneric, StructMethodRet, @@ -29,6 +31,7 @@ struct Struct { StructEmbed v StructField ref &StructRefField + map map[StructMapFieldKey]StructMapFieldValue } fn (s Struct) method(v StructMethodArg) StructMethodRet { diff --git a/vlib/v/fmt/tests/import_selective_input.vv b/vlib/v/fmt/tests/import_selective_input.vv index c5e2dd4d5f..1433b0e6c3 100644 --- a/vlib/v/fmt/tests/import_selective_input.vv +++ b/vlib/v/fmt/tests/import_selective_input.vv @@ -10,6 +10,7 @@ import os { import mod { Unused, StructEmbed, StructField, StructRefField + StructMapFieldKey, StructMapFieldValue, StructMethodArg, StructMethodArgGeneric, StructMethodRet, @@ -34,6 +35,7 @@ struct Struct { StructEmbed v StructField ref &StructRefField + map map[StructMapFieldKey]StructMapFieldValue } fn (s Struct) method(v StructMethodArg) StructMethodRet {