fmt: keep names of parameters in anonymus function (#10173)
parent
efa07cbcbf
commit
79b97fa361
|
@ -31,7 +31,6 @@ const (
|
|||
// TODOs and unfixed vfmt bugs
|
||||
'vlib/builtin/int.v' /* TODO byteptr: vfmt converts `pub fn (nn byteptr) str() string {` to `nn &byte` and that conflicts with `nn byte` */,
|
||||
'vlib/builtin/string_charptr_byteptr_helpers.v' /* TODO byteptr: a temporary shim to ease the byteptr=>&byte transition */,
|
||||
'vlib/v/tests/fn_high_test.v', /* param name removed */
|
||||
'vlib/v/tests/interop_test.v', /* bad comment formatting */
|
||||
'vlib/v/tests/string_interpolation_test.v' /* TODO byteptr: &byte.str() behaves differently than byteptr.str() */,
|
||||
'vlib/v/gen/js/tests/js.v', /* local `hello` fn, gets replaced with module `hello` aliased as `hl` */
|
||||
|
|
|
@ -184,8 +184,12 @@ pub fn (t &Table) fn_type_source_signature(f &Fn) string {
|
|||
if arg.is_mut {
|
||||
sig += 'mut '
|
||||
}
|
||||
// NB: arg name is only added for fmt, else it would causes errors with generics
|
||||
if t.is_fmt && arg.name.len > 0 {
|
||||
sig += '$arg.name '
|
||||
}
|
||||
arg_type_sym := t.get_type_symbol(arg.typ)
|
||||
sig += '$arg_type_sym.name'
|
||||
sig += arg_type_sym.name
|
||||
if i < f.params.len - 1 {
|
||||
sig += ', '
|
||||
}
|
||||
|
@ -854,7 +858,6 @@ pub fn (mut t Table) find_or_register_fn_type(mod string, f Fn, is_anon bool, ha
|
|||
util.no_dots(f.name.clone())
|
||||
}
|
||||
anon := f.name.len == 0 || is_anon
|
||||
// existing
|
||||
existing_idx := t.type_idxs[name]
|
||||
if existing_idx > 0 && t.type_symbols[existing_idx].kind != .placeholder {
|
||||
return existing_idx
|
||||
|
|
|
@ -909,7 +909,10 @@ pub fn (t &Table) type_to_str_using_aliases(typ Type, import_aliases map[string]
|
|||
} else {
|
||||
if res.starts_with('fn (') {
|
||||
// fn foo ()
|
||||
res = t.fn_signature_using_aliases(info.func, import_aliases, type_only: true)
|
||||
has_names := info.func.params.any(it.name.len > 0)
|
||||
res = t.fn_signature_using_aliases(info.func, import_aliases,
|
||||
type_only: !has_names
|
||||
)
|
||||
} else {
|
||||
// FnFoo
|
||||
res = t.shorten_user_defined_typenames(res, import_aliases)
|
||||
|
|
|
@ -1,11 +1,20 @@
|
|||
struct Row {
|
||||
id int
|
||||
import v.ast
|
||||
|
||||
struct Data {
|
||||
a fn (stmt ast.Stmt, vp voidptr) bool
|
||||
}
|
||||
|
||||
pub fn (a []Row) reduce(iter fn (int, int) int, accum_start int) int {
|
||||
pub fn (a []Data) reduce(iter fn (int, int) int, accum_start int) int {
|
||||
iter(accum_start)
|
||||
}
|
||||
|
||||
pub fn test_anon_fn_void(func fn ()) int {
|
||||
return 0
|
||||
}
|
||||
|
||||
fn C.HasAnonFnWithNamedParams(cb fn (c C.bar, d voidptr))
|
||||
|
||||
// NB: the signature of both anonymus functions should only differs in the param name
|
||||
fn anon_fn_param_has_no_name(f fn (int) string) {}
|
||||
|
||||
fn anon_fn_with_named_param(func fn (a int) string) {}
|
||||
|
|
|
@ -1,6 +0,0 @@
|
|||
import v.ast
|
||||
|
||||
struct Data {
|
||||
a fn (string, voidptr) bool
|
||||
b fn (ast.Stmt, voidptr) bool
|
||||
}
|
|
@ -1,6 +0,0 @@
|
|||
import v.ast
|
||||
|
||||
struct Data {
|
||||
a fn (s string, f voidptr) bool
|
||||
b fn (stmt ast.Stmt, f voidptr) bool
|
||||
}
|
Loading…
Reference in New Issue