diff --git a/vlib/v/fmt/fmt.v b/vlib/v/fmt/fmt.v index df98c768e2..e4f7f0bdc7 100644 --- a/vlib/v/fmt/fmt.v +++ b/vlib/v/fmt/fmt.v @@ -235,7 +235,8 @@ 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) - f.mark_import_as_used(sym.name) + name := sym.name.split('<')[0] // take `Type` from `Type` + f.mark_import_as_used(name) } // `name` is a function (`foo.bar()`) or type (`foo.Bar{}`) diff --git a/vlib/v/fmt/tests/import_selective_expected.vv b/vlib/v/fmt/tests/import_selective_expected.vv index fa72af77f1..66e4621ff6 100644 --- a/vlib/v/fmt/tests/import_selective_expected.vv +++ b/vlib/v/fmt/tests/import_selective_expected.vv @@ -8,7 +8,9 @@ import os { import mod { Enum, FnArg, + FnArgGeneric, FnRet, + FnRetGeneric, InterfaceField, InterfaceMethodArg, InterfaceMethodRet, @@ -17,7 +19,9 @@ import mod { StructEmbed, StructField, StructMethodArg, + StructMethodArgGeneric, StructMethodRet, + StructMethodRetGeneric, StructRefField, } @@ -31,6 +35,10 @@ fn (s Struct) method(v StructMethodArg) StructMethodRet { return StructMethodRet{} } +fn (s Struct) method_generic(v StructMethodArgGeneric) StructMethodRetGeneric { + return StructMethodRet{} +} + interface Interface { v InterfaceField f(InterfaceMethodArg) InterfaceMethodRet @@ -46,6 +54,10 @@ fn f(v FnArg) FnRet { return FnRet{} } +fn f_generic(v FnArgGeneric) FnRetGeneric { + return FnRetGeneric{} +} + struct App { command &Command } diff --git a/vlib/v/fmt/tests/import_selective_input.vv b/vlib/v/fmt/tests/import_selective_input.vv index 534b72e593..c5e2dd4d5f 100644 --- a/vlib/v/fmt/tests/import_selective_input.vv +++ b/vlib/v/fmt/tests/import_selective_input.vv @@ -11,14 +11,18 @@ import mod { Unused, StructEmbed, StructField, StructRefField StructMethodArg, - StructMethodRet + StructMethodArgGeneric, + StructMethodRet, + StructMethodRetGeneric, InterfaceField, InterfaceMethodArg, InterfaceMethodRet, FnArg, + FnArgGeneric FnRet, + FnRetGeneric RightOfIs, RightOfAs, @@ -36,6 +40,10 @@ fn (s Struct) method(v StructMethodArg) StructMethodRet { return StructMethodRet{} } +fn (s Struct) method_generic(v StructMethodArgGeneric) StructMethodRetGeneric { + return StructMethodRet{} +} + interface Interface { v InterfaceField f(InterfaceMethodArg) InterfaceMethodRet @@ -50,6 +58,10 @@ fn f(v FnArg) FnRet { return FnRet{} } +fn f_generic(v FnArgGeneric) FnRetGeneric { + return FnRetGeneric{} +} + struct App { command &Command }