1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

fmt: fix removal of selective imported generic type (#11395)

This commit is contained in:
zakuro 2021-09-05 23:59:35 +09:00 committed by GitHub
parent 6b55b6d417
commit aefe267970
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 27 additions and 2 deletions

View File

@ -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<T>`
f.mark_import_as_used(name)
}
// `name` is a function (`foo.bar()`) or type (`foo.Bar{}`)

View File

@ -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<T>(v StructMethodArgGeneric<T>) StructMethodRetGeneric<T> {
return StructMethodRet<T>{}
}
interface Interface {
v InterfaceField
f(InterfaceMethodArg) InterfaceMethodRet
@ -46,6 +54,10 @@ fn f(v FnArg) FnRet {
return FnRet{}
}
fn f_generic<T>(v FnArgGeneric<T>) FnRetGeneric<T> {
return FnRetGeneric<T>{}
}
struct App {
command &Command
}

View File

@ -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<T>(v StructMethodArgGeneric<T>) StructMethodRetGeneric<T> {
return StructMethodRet<T>{}
}
interface Interface {
v InterfaceField
f(InterfaceMethodArg) InterfaceMethodRet
@ -50,6 +58,10 @@ fn f(v FnArg) FnRet {
return FnRet{}
}
fn f_generic<T>(v FnArgGeneric<T>) FnRetGeneric<T> {
return FnRetGeneric<T>{}
}
struct App {
command &Command
}