fmt: fix bug that adds unnecessary module name to generic types (#12758)

pull/12769/head
zakuro 2021-12-09 05:33:58 +09:00 committed by GitHub
parent d88e67a5ec
commit 7379488cee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 7 additions and 6 deletions

View File

@ -1054,16 +1054,15 @@ pub fn (t &Table) type_to_str_using_aliases(typ Type, import_aliases map[string]
}
.generic_inst {
info := sym.info as GenericInst
res = sym.name.all_before('<')
res = t.shorten_user_defined_typenames(sym.name.all_before('<'), import_aliases)
res += '<'
for i, ctyp in info.concrete_types {
res += t.get_type_symbol(ctyp).name
res += t.type_to_str_using_aliases(ctyp, import_aliases)
if i != info.concrete_types.len - 1 {
res += ', '
}
}
res += '>'
res = t.shorten_user_defined_typenames(res, import_aliases)
}
.void {
if typ.has_flag(.optional) {

View File

@ -1,4 +1,4 @@
import mymod { ImpNode }
import mymod { Data, ImpNode }
fn foobar_mymod<U>(inode ImpNode<U>) ImpNode<U> {
return ImpNode{}
@ -14,7 +14,9 @@ fn (_ Foo) simple<T>() T {
return T{}
}
struct GenericStruct<A, B> {}
struct GenericStruct<A, B> {
v Data<Data<A>, B>
}
fn proper_generics(gs GenericStruct<A, B>) GenericStruct<A, B> {
return gs

View File

@ -573,7 +573,7 @@ fn test_generic_detection() {
})
// this final case challenges your scanner :-)
assert boring_function<TandU<TandU<int,MultiLevel<Empty_>>, map[string][]int>>(TandU<TandU<int,MultiLevel<Empty_>>, map[string][]int>{
assert boring_function<TandU<TandU<int, MultiLevel<Empty_>>, map[string][]int>>(TandU<TandU<int,MultiLevel<Empty_>>, map[string][]int>{
t: TandU<int,MultiLevel<Empty_>>{
t: 20
u: MultiLevel<Empty_>{