fmt: fix removal of selective imported types used as type parameter (#12431)

pull/12435/head
zakuro 2021-11-11 14:15:30 +09:00 committed by GitHub
parent 72a7d5a559
commit 823a3ab838
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 0 deletions

View File

@ -251,6 +251,11 @@ pub fn (mut f Fmt) mark_types_import_as_used(typ ast.Type) {
f.mark_types_import_as_used(map_info.value_type) f.mark_types_import_as_used(map_info.value_type)
return return
} }
if sym.info is ast.GenericInst {
for concrete_typ in sym.info.concrete_types {
f.mark_types_import_as_used(concrete_typ)
}
}
name := sym.name.split('<')[0] // take `Type` from `Type<T>` name := sym.name.split('<')[0] // take `Type` from `Type<T>`
f.mark_import_as_used(name) f.mark_import_as_used(name)
} }

View File

@ -9,8 +9,12 @@ import mod {
Enum, Enum,
FnArg, FnArg,
FnArgGeneric, FnArgGeneric,
FnArgTypeParam1,
FnArgTypeParam2,
FnRet, FnRet,
FnRetGeneric, FnRetGeneric,
FnRetTypeParam1,
FnRetTypeParam2,
InterfaceField, InterfaceField,
InterfaceMethodArg, InterfaceMethodArg,
InterfaceMethodRet, InterfaceMethodRet,
@ -57,6 +61,8 @@ fn f(v FnArg) FnRet {
return FnRet{} return FnRet{}
} }
fn f2(v Generic<FnArgTypeParam1, FnArgTypeParam2>) Generic<FnRetTypeParam1, FnRetTypeParam2> {}
fn f_generic<T>(v FnArgGeneric<T>) FnRetGeneric<T> { fn f_generic<T>(v FnArgGeneric<T>) FnRetGeneric<T> {
return FnRetGeneric<T>{} return FnRetGeneric<T>{}
} }

View File

@ -22,8 +22,12 @@ import mod {
FnArg, FnArg,
FnArgGeneric FnArgGeneric
FnArgTypeParam1
FnArgTypeParam2
FnRet, FnRet,
FnRetGeneric FnRetGeneric
FnRetTypeParam1,
FnRetTypeParam2,
RightOfIs, RightOfIs,
RightOfAs, RightOfAs,
@ -60,6 +64,8 @@ fn f(v FnArg) FnRet {
return FnRet{} return FnRet{}
} }
fn f2(v Generic<FnArgTypeParam1, FnArgTypeParam2>) Generic<FnRetTypeParam1, FnRetTypeParam2> {}
fn f_generic<T>(v FnArgGeneric<T>) FnRetGeneric<T> { fn f_generic<T>(v FnArgGeneric<T>) FnRetGeneric<T> {
return FnRetGeneric<T>{} return FnRetGeneric<T>{}
} }