mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
vfmt: fix type MyFn = fn (int) int mut arr := []MyFn{}
This commit is contained in:
parent
3b6b5b8090
commit
338f3afd31
4
vlib/v/fmt/tests/fntype_alias_array_keep.vv
Normal file
4
vlib/v/fmt/tests/fntype_alias_array_keep.vv
Normal file
@ -0,0 +1,4 @@
|
||||
type MyFn = fn (int) int
|
||||
|
||||
mut arr := []MyFn{}
|
||||
arr << MyFn(test)
|
@ -885,6 +885,8 @@ pub fn (table &Table) type_to_str_using_aliases(t Type, import_aliases map[strin
|
||||
if !table.is_fmt {
|
||||
info := sym.info as FnType
|
||||
res = table.fn_signature(info.func, type_only: true)
|
||||
} else {
|
||||
res = table.shorten_user_defined_typenames(res, import_aliases)
|
||||
}
|
||||
}
|
||||
.map {
|
||||
@ -914,17 +916,7 @@ pub fn (table &Table) type_to_str_using_aliases(t Type, import_aliases map[strin
|
||||
return 'void'
|
||||
}
|
||||
else {
|
||||
// types defined by the user
|
||||
// mod.submod.submod2.Type => submod2.Type
|
||||
parts := res.split('.')
|
||||
res = if parts.len > 1 { parts[parts.len - 2..].join('.') } else { parts[0] }
|
||||
// cur_mod.Type => Type
|
||||
if res.starts_with(table.cmod_prefix) {
|
||||
res = res.replace_once(table.cmod_prefix, '')
|
||||
}
|
||||
if res in import_aliases {
|
||||
res = import_aliases[res]
|
||||
}
|
||||
res = table.shorten_user_defined_typenames(res, import_aliases)
|
||||
}
|
||||
}
|
||||
nr_muls := t.nr_muls()
|
||||
@ -937,6 +929,22 @@ pub fn (table &Table) type_to_str_using_aliases(t Type, import_aliases map[strin
|
||||
return res
|
||||
}
|
||||
|
||||
fn (t Table) shorten_user_defined_typenames(originalname string, import_aliases map[string]string) string {
|
||||
mut res := originalname
|
||||
// types defined by the user
|
||||
// mod.submod.submod2.Type => submod2.Type
|
||||
parts := res.split('.')
|
||||
res = if parts.len > 1 { parts[parts.len - 2..].join('.') } else { parts[0] }
|
||||
// cur_mod.Type => Type
|
||||
if res.starts_with(t.cmod_prefix) {
|
||||
res = res.replace_once(t.cmod_prefix, '')
|
||||
}
|
||||
if res in import_aliases {
|
||||
res = import_aliases[res]
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
pub struct FnSignatureOpts {
|
||||
skip_receiver bool
|
||||
type_only bool
|
||||
|
Loading…
Reference in New Issue
Block a user