fmt: keep generics for selective import as fn param (#10138)
parent
de080ba149
commit
be189e0059
|
@ -848,12 +848,6 @@ pub fn (mytable &Table) type_to_code(t Type) string {
|
||||||
|
|
||||||
// import_aliases is a map of imported symbol aliases 'module.Type' => 'Type'
|
// import_aliases is a map of imported symbol aliases 'module.Type' => 'Type'
|
||||||
pub fn (t &Table) type_to_str_using_aliases(typ Type, import_aliases map[string]string) string {
|
pub fn (t &Table) type_to_str_using_aliases(typ Type, import_aliases map[string]string) string {
|
||||||
/*
|
|
||||||
if t.pref.is_verbose {
|
|
||||||
print_backtrace()
|
|
||||||
exit(0)
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
sym := t.get_type_symbol(typ)
|
sym := t.get_type_symbol(typ)
|
||||||
mut res := sym.name
|
mut res := sym.name
|
||||||
match sym.kind {
|
match sym.kind {
|
||||||
|
@ -957,6 +951,19 @@ pub fn (t &Table) type_to_str_using_aliases(typ Type, import_aliases map[string]
|
||||||
res = t.shorten_user_defined_typenames(res, import_aliases)
|
res = t.shorten_user_defined_typenames(res, import_aliases)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
.generic_struct_inst {
|
||||||
|
info := sym.info as GenericStructInst
|
||||||
|
res = sym.name.all_before('<')
|
||||||
|
res += '<'
|
||||||
|
for i, ctyp in info.concrete_types {
|
||||||
|
res += t.get_type_symbol(ctyp).name
|
||||||
|
if i != info.concrete_types.len - 1 {
|
||||||
|
res += ', '
|
||||||
|
}
|
||||||
|
}
|
||||||
|
res += '>'
|
||||||
|
res = t.shorten_user_defined_typenames(res, import_aliases)
|
||||||
|
}
|
||||||
.void {
|
.void {
|
||||||
if typ.has_flag(.optional) {
|
if typ.has_flag(.optional) {
|
||||||
return '?'
|
return '?'
|
||||||
|
|
|
@ -1,3 +1,9 @@
|
||||||
|
import mymod { ImpNode }
|
||||||
|
|
||||||
|
fn foobar_mymod<U>(inode ImpNode<U>) ImpNode<U> {
|
||||||
|
return ImpNode{}
|
||||||
|
}
|
||||||
|
|
||||||
fn simple<T>() T {
|
fn simple<T>() T {
|
||||||
return T{}
|
return T{}
|
||||||
}
|
}
|
||||||
|
@ -8,6 +14,18 @@ fn (_ Foo) simple<T>() T {
|
||||||
return T{}
|
return T{}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct NonGenericStruct {}
|
||||||
|
|
||||||
|
fn use_as_generic(ngs NonGenericStruct<V>) NonGenericStruct<V> {
|
||||||
|
return NonGenericStruct{}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct GenericStruct<A, B> {}
|
||||||
|
|
||||||
|
fn proper_generics(gs GenericStruct<A, B>) GenericStruct<A, B> {
|
||||||
|
return gs
|
||||||
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
simple<int>()
|
simple<int>()
|
||||||
Foo{}.simple<int>()
|
Foo{}.simple<int>()
|
||||||
|
|
|
@ -536,7 +536,8 @@ pub fn (mut p Parser) parse_generic_struct_inst_type(name string) ast.Type {
|
||||||
p.check(.gt)
|
p.check(.gt)
|
||||||
p.in_generic_params = false
|
p.in_generic_params = false
|
||||||
bs_name += '>'
|
bs_name += '>'
|
||||||
if is_instance && concrete_types.len > 0 {
|
// fmt operates on a per-file basis, so is_instance might be not set correctly. Thus it's ignored.
|
||||||
|
if (is_instance || p.pref.is_fmt) && concrete_types.len > 0 {
|
||||||
mut gt_idx := p.table.find_type_idx(bs_name)
|
mut gt_idx := p.table.find_type_idx(bs_name)
|
||||||
if gt_idx > 0 {
|
if gt_idx > 0 {
|
||||||
return ast.new_type(gt_idx)
|
return ast.new_type(gt_idx)
|
||||||
|
|
Loading…
Reference in New Issue