mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
fmt: fix multiple problems with types (#6603)
This commit is contained in:
parent
230e9868d1
commit
93bb7564dc
3
vlib/v/fmt/tests/anon_fn_as_param_keep.vv
Normal file
3
vlib/v/fmt/tests/anon_fn_as_param_keep.vv
Normal file
@ -0,0 +1,3 @@
|
||||
pub fn (a []int) reduce(iter fn (int, int) int, accum_start int) int {
|
||||
iter(accum_start)
|
||||
}
|
3
vlib/v/fmt/tests/fixed_size_array_type_keep.vv
Normal file
3
vlib/v/fmt/tests/fixed_size_array_type_keep.vv
Normal file
@ -0,0 +1,3 @@
|
||||
fn foo() [1]f32 {
|
||||
return [f32(0.0)]!!
|
||||
}
|
6
vlib/v/fmt/tests/nested_map_type_keep.vv
Normal file
6
vlib/v/fmt/tests/nested_map_type_keep.vv
Normal file
@ -0,0 +1,6 @@
|
||||
import v.ast
|
||||
|
||||
// TODO fix `fn foo(my_map map[string]map[string]int) []ast.FnDecl {`
|
||||
fn foo(my_map map[string]map[string]int) int {
|
||||
return 0
|
||||
}
|
@ -801,7 +801,9 @@ pub:
|
||||
pub fn (table &Table) type_to_str(t Type) string {
|
||||
sym := table.get_type_symbol(t)
|
||||
mut res := sym.name
|
||||
if sym.kind == .multi_return {
|
||||
if sym.kind in [.array_fixed, .function] {
|
||||
res = sym.source_name
|
||||
} else if sym.kind == .multi_return {
|
||||
res = '('
|
||||
if t.has_flag(.optional) {
|
||||
res = '?' + res
|
||||
|
@ -361,17 +361,20 @@ pub fn no_dots(s string) string {
|
||||
return s.replace('.', '__')
|
||||
}
|
||||
|
||||
const (
|
||||
map_prefix = 'map[string]'
|
||||
)
|
||||
|
||||
// no_cur_mod - removes cur_mod. prefix from typename,
|
||||
// but *only* when it is at the start, i.e.:
|
||||
// no_cur_mod('vproto.Abdcdef', 'proto') == 'vproto.Abdcdef'
|
||||
// even though proto. is a substring
|
||||
pub fn no_cur_mod(typename, cur_mod string) string {
|
||||
mut res := typename
|
||||
map_prefix := 'map[string]'
|
||||
mod_prefix := cur_mod + '.'
|
||||
has_map_prefix := res.starts_with(map_prefix)
|
||||
if has_map_prefix {
|
||||
res = res.replace(map_prefix, '')
|
||||
res = res.replace_once(map_prefix, '')
|
||||
}
|
||||
no_symbols := res.trim_left('&[]')
|
||||
should_shorten := no_symbols.starts_with(mod_prefix)
|
||||
|
Loading…
Reference in New Issue
Block a user