From 4ba2b1c8d70b0d9cd2cd80cf6dadd8dfb62d3009 Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Tue, 26 May 2026 23:50:55 +0300 Subject: [PATCH] all: fix fn shadowing warning --- vlib/cli/command.v | 3 +- vlib/v/depgraph/depgraph.v | 8 +-- vlib/v/gen/c/auto_str_methods.v | 12 ++-- vlib/v/gen/c/cgen.v | 6 +- vlib/v/gen/c/fn.v | 6 +- vlib/v/gen/c/json.v | 8 +-- vlib/v/gen/c/match.v | 4 +- vlib/v/generics/generics.v | 70 +++++++++---------- vlib/v/parser/module.v | 20 +++--- .../interface_to_ptr_interface_as_cast_test.v | 4 +- ...ared_library_boehm_register_threads_test.v | 3 +- 11 files changed, 73 insertions(+), 71 deletions(-) diff --git a/vlib/cli/command.v b/vlib/cli/command.v index 24c61bc57..75897a174 100644 --- a/vlib/cli/command.v +++ b/vlib/cli/command.v @@ -406,8 +406,7 @@ fn (cmd &Command) check_required_flags() { // execute_help executes the callback registered for the `-h`/`--help` flag option. pub fn (cmd &Command) execute_help() { if cmd.commands.contains('help') { - sub := - cmd.commands.get('help') or { return } // ignore error and handle command normally + sub := cmd.commands.get('help') or { return } // ignore error and handle command normally if !isnil(sub.execute) { sub.execute(sub) or { panic(err) } return diff --git a/vlib/v/depgraph/depgraph.v b/vlib/v/depgraph/depgraph.v index 9aaf35d9b..d99d53baa 100644 --- a/vlib/v/depgraph/depgraph.v +++ b/vlib/v/depgraph/depgraph.v @@ -93,21 +93,21 @@ pub fn new_dep_graph() &DepGraph { } pub fn (mut graph DepGraph) add(mod string, deps []string) { - new_node := DepGraphNode{ + node := DepGraphNode{ name: mod deps: deps.clone() } - graph.nodes << new_node + graph.nodes << node graph.values[mod] = 0 } pub fn (mut graph DepGraph) add_with_value(mod string, deps []string, value i64) { - new_node := DepGraphNode{ + node := DepGraphNode{ name: mod value: value deps: deps.clone() } - graph.nodes << new_node + graph.nodes << node graph.values[mod] = value } diff --git a/vlib/v/gen/c/auto_str_methods.v b/vlib/v/gen/c/auto_str_methods.v index c9901ad45..8e5c720a8 100644 --- a/vlib/v/gen/c/auto_str_methods.v +++ b/vlib/v/gen/c/auto_str_methods.v @@ -930,12 +930,12 @@ fn (mut g Gen) gen_str_for_map(info ast.Map, styp string, str_fn_name string) { g.auto_str_funcs.writeln('\t\tstrings__Builder_write_string(&sb, ${tmp_str});') } } else if should_use_indent_func(val_sym.kind) && fn_str.name != 'str' { - ptr_str := if !is_option && val_sym.is_c_struct() && str_method_expects_ptr { + deref := if !is_option && val_sym.is_c_struct() && str_method_expects_ptr { '' } else { '*'.repeat(val_typ.nr_muls() + 1) } - g.auto_str_funcs.writeln('\t\tstrings__Builder_write_string(&sb, indent_${elem_str_fn_name}(${ptr_str}(${val_styp}*)builtin__DenseArray_value(&m.key_values, i), indent_count));') + g.auto_str_funcs.writeln('\t\tstrings__Builder_write_string(&sb, indent_${elem_str_fn_name}(${deref}(${val_styp}*)builtin__DenseArray_value(&m.key_values, i), indent_count));') } else if val_sym.kind in [.f32, .f64] { tmp_val := '*(${val_styp}*)builtin__DenseArray_value(&m.key_values, i)' if val_typ.has_flag(.option) { @@ -952,13 +952,13 @@ fn (mut g Gen) gen_str_for_map(info ast.Map, styp string, str_fn_name string) { str_intp_rune('${elem_str_fn_name}(*(${val_styp}*)builtin__DenseArray_value(&m.key_values, i))') g.auto_str_funcs.writeln('\t\tstrings__Builder_write_string(&sb, ${tmp_str});') } else { - ptr_str := '*'.repeat(val_typ.nr_muls()) + deref := '*'.repeat(val_typ.nr_muls()) if val_typ.has_flag(.option) { - g.auto_str_funcs.writeln('\t\tstrings__Builder_write_string(&sb, ${g.get_str_fn(val_typ)}(*${ptr_str}(${val_styp}*)builtin__DenseArray_value(&m.key_values, i)));') + g.auto_str_funcs.writeln('\t\tstrings__Builder_write_string(&sb, ${g.get_str_fn(val_typ)}(*${deref}(${val_styp}*)builtin__DenseArray_value(&m.key_values, i)));') } else if receiver_is_ptr { - g.auto_str_funcs.writeln('\t\tstrings__Builder_write_string(&sb, ${elem_str_fn_name}(${ptr_str}(${val_styp}*)builtin__DenseArray_value(&m.key_values, i)));') + g.auto_str_funcs.writeln('\t\tstrings__Builder_write_string(&sb, ${elem_str_fn_name}(${deref}(${val_styp}*)builtin__DenseArray_value(&m.key_values, i)));') } else { - g.auto_str_funcs.writeln('\t\tstrings__Builder_write_string(&sb, ${elem_str_fn_name}(*${ptr_str}(${val_styp}*)builtin__DenseArray_value(&m.key_values, i)));') + g.auto_str_funcs.writeln('\t\tstrings__Builder_write_string(&sb, ${elem_str_fn_name}(*${deref}(${val_styp}*)builtin__DenseArray_value(&m.key_values, i)));') } } g.auto_str_funcs.writeln('\t\tis_first = false;') diff --git a/vlib/v/gen/c/cgen.v b/vlib/v/gen/c/cgen.v index 6eea7dde0..4d05da8b6 100644 --- a/vlib/v/gen/c/cgen.v +++ b/vlib/v/gen/c/cgen.v @@ -8378,10 +8378,10 @@ fn (mut g Gen) enum_decl(node ast.EnumDecl) { // @[typedef] enums are already defined in a C header — don't redefine the enum, // but emit #define aliases so that V-mangled field names resolve to the correct values. if node.attrs.contains('typedef') { - c_name := node.name.all_after_last('.') + header_name := node.name.all_after_last('.') g.enum_typedefs.writeln('') - g.enum_typedefs.writeln('// @[typedef] enum ${c_name} — defined in C header') - g.enum_typedefs.writeln('typedef ${c_name} ${enum_name};') + g.enum_typedefs.writeln('// @[typedef] enum ${header_name} — defined in C header') + g.enum_typedefs.writeln('typedef ${header_name} ${enum_name};') mut cur_value := 0 for field in node.fields { if field.has_expr { diff --git a/vlib/v/gen/c/fn.v b/vlib/v/gen/c/fn.v index 63861c767..e412df817 100644 --- a/vlib/v/gen/c/fn.v +++ b/vlib/v/gen/c/fn.v @@ -1376,11 +1376,11 @@ fn (mut g Gen) gen_fn_decl(node &ast.FnDecl, skip bool) { } } } else if g.inside_c_extern { - c_name := name.all_after_first('C__') + extern_name := name.all_after_first('C__') // Guard with #ifndef so the declaration is skipped when the C symbol // is actually a preprocessor macro (e.g. WIFSTOPPED from ). - g.definitions.writeln('#ifndef ${c_name}') - c_extern_fn_header := 'extern ${type_name} ${fn_attrs}${c_name}(' + g.definitions.writeln('#ifndef ${extern_name}') + c_extern_fn_header := 'extern ${type_name} ${fn_attrs}${extern_name}(' g.definitions.write_string(c_extern_fn_header) } else { if !(node.is_pub || g.pref.is_debug) { diff --git a/vlib/v/gen/c/json.v b/vlib/v/gen/c/json.v index c615f7201..ae9ed5ecf 100644 --- a/vlib/v/gen/c/json.v +++ b/vlib/v/gen/c/json.v @@ -1252,18 +1252,18 @@ fn (mut g Gen) encode_array(utyp ast.Type, value_type ast.Type, fixed_array_size styp := g.styp(value_type) fn_name := js_enc_name(styp) - mut data_str := '' + mut data_expr := '' mut size_str := '' if utyp.has_flag(.option) { - data_str, size_str = if fixed_array_size > -1 { + data_expr, size_str = if fixed_array_size > -1 { // fixed array '(${styp}*)(*(${g.base_type(utyp)}*)val.data)', '${fixed_array_size}' } else { '(${styp}*)(*(${g.base_type(utyp)}*)val.data).data', '(*(${g.base_type(utyp)}*)val.data).len' } } else { - data_str, size_str = if fixed_array_size > -1 { + data_expr, size_str = if fixed_array_size > -1 { // fixed array '(${styp}*)val', '${fixed_array_size}' } else { @@ -1274,7 +1274,7 @@ fn (mut g Gen) encode_array(utyp ast.Type, value_type ast.Type, fixed_array_size return ' o = cJSON_CreateArray(); for (${ast.int_type_name} i = 0; i < ${size_str}; i++){ - cJSON_AddItemToArray(o, ${fn_name}( (${data_str})[i] )); + cJSON_AddItemToArray(o, ${fn_name}( (${data_expr})[i] )); } ' } diff --git a/vlib/v/gen/c/match.v b/vlib/v/gen/c/match.v index ceb4d27b2..9acff4574 100644 --- a/vlib/v/gen/c/match.v +++ b/vlib/v/gen/c/match.v @@ -552,8 +552,8 @@ fn (mut g Gen) match_expr_classic(node ast.MatchExpr, is_expr bool, cond_var str g.write('_SLIT_EQ(${cond_var}.str, ${cond_var}.len, "${slit}")') } } else { - ptr_str := if node.cond_type.is_ptr() { '*' } else { '' } - g.write('builtin__fast_string_eq(${ptr_str}${cond_var}, ') + deref := if node.cond_type.is_ptr() { '*' } else { '' } + g.write('builtin__fast_string_eq(${deref}${cond_var}, ') g.expr(expr) g.write(')') } diff --git a/vlib/v/generics/generics.v b/vlib/v/generics/generics.v index ecd012fc8..564c39e0c 100644 --- a/vlib/v/generics/generics.v +++ b/vlib/v/generics/generics.v @@ -236,7 +236,7 @@ pub fn (mut g Generics) stmt(mut node ast.Stmt) ast.Stmt { g.forin_types.delete(node.val_var) } } - mut new_node := ast.ForInStmt{ + mut for_in := ast.ForInStmt{ ...node cond: g.expr(mut node.cond) high: g.expr(mut node.high) @@ -246,7 +246,7 @@ pub fn (mut g Generics) stmt(mut node ast.Stmt) ast.Stmt { high_type: g.unwrap_generic(node.high_type) stmts: g.stmts(mut stmts) } - return ast.Stmt(new_node) + return ast.Stmt(for_in) } node.stmts = g.stmts(mut node.stmts) } @@ -521,54 +521,54 @@ pub fn (mut g Generics) generic_fn_decl(mut node ast.FnDecl) []ast.Stmt { } g.cur_concrete_types = concrete_types - mut new_node := ast.FnDecl{ + mut fn_decl := ast.FnDecl{ ...node } - new_node = g.stmt(mut new_node) as ast.FnDecl - new_node = ast.FnDecl{ - ...new_node + fn_decl = g.stmt(mut fn_decl) as ast.FnDecl + fn_decl = ast.FnDecl{ + ...fn_decl name: if node.is_method { - g.method_concrete_name(new_node.name, concrete_types, new_node.receiver.typ) + g.method_concrete_name(fn_decl.name, concrete_types, fn_decl.receiver.typ) } else { - g.concrete_name(new_node.name, concrete_types) + g.concrete_name(fn_decl.name, concrete_types) } ninstances: 0 generic_names: [] } - if new_node.is_method { - mut sym := g.table.sym(new_node.receiver.typ) + if fn_decl.is_method { + mut sym := g.table.sym(fn_decl.receiver.typ) func := ast.Fn{ - is_variadic: new_node.is_variadic - is_c_variadic: new_node.is_c_variadic + is_variadic: fn_decl.is_variadic + is_c_variadic: fn_decl.is_c_variadic language: .v - is_pub: new_node.is_pub - is_deprecated: new_node.is_deprecated - is_noreturn: new_node.is_noreturn - is_unsafe: new_node.is_unsafe - is_must_use: new_node.is_must_use - is_keep_alive: new_node.is_keep_alive - is_method: new_node.is_method - is_static_type_method: new_node.is_static_type_method - no_body: new_node.no_body - is_file_translated: new_node.is_file_translated - mod: new_node.mod - file: new_node.file - file_mode: new_node.file_mode - pos: new_node.pos - return_type_pos: new_node.return_type_pos - return_type: new_node.return_type - receiver_type: new_node.receiver.typ - name: new_node.name - params: new_node.params + is_pub: fn_decl.is_pub + is_deprecated: fn_decl.is_deprecated + is_noreturn: fn_decl.is_noreturn + is_unsafe: fn_decl.is_unsafe + is_must_use: fn_decl.is_must_use + is_keep_alive: fn_decl.is_keep_alive + is_method: fn_decl.is_method + is_static_type_method: fn_decl.is_static_type_method + no_body: fn_decl.no_body + is_file_translated: fn_decl.is_file_translated + mod: fn_decl.mod + file: fn_decl.file + file_mode: fn_decl.file_mode + pos: fn_decl.pos + return_type_pos: fn_decl.return_type_pos + return_type: fn_decl.return_type + receiver_type: fn_decl.receiver.typ + name: fn_decl.name + params: fn_decl.params generic_names: [] - is_conditional: new_node.is_conditional - ctdefine_idx: new_node.ctdefine_idx - is_expand_simple_interpolation: new_node.is_expand_simple_interpolation + is_conditional: fn_decl.is_conditional + ctdefine_idx: fn_decl.ctdefine_idx + is_expand_simple_interpolation: fn_decl.is_expand_simple_interpolation } g.table.find_or_register_fn_type(func, false, true) sym.register_method(func) } - solved_fns << new_node + solved_fns << fn_decl } g.cur_concrete_types = [] return solved_fns diff --git a/vlib/v/parser/module.v b/vlib/v/parser/module.v index 37334eb36..d85762609 100644 --- a/vlib/v/parser/module.v +++ b/vlib/v/parser/module.v @@ -213,20 +213,20 @@ fn (mut p Parser) import_stmt() ast.Import { p.error_with_pos('`import()` has been deprecated, use `import x` instead', pos) return import_node } - mut source_name := p.check_name() - if source_name == '' { + mut src_name := p.check_name() + if src_name == '' { p.error_with_pos('import name can not be empty', pos) return import_node } mut mod_name_arr := []string{} - mod_name_arr << source_name + mod_name_arr << src_name if import_pos.line_nr != pos.line_nr { p.error_with_pos('`import` statements must be a single line', pos) return import_node } mut mod_alias := mod_name_arr[0] import_node = ast.Import{ - source_name: source_name + source_name: src_name pos: import_pos.extend(pos) mod_pos: pos alias_pos: pos @@ -246,19 +246,19 @@ fn (mut p Parser) import_stmt() ast.Import { mod_name_arr << submod_name mod_alias = submod_name pos = pos.extend(submod_pos) - source_name = mod_name_arr.join('.') + src_name = mod_name_arr.join('.') import_node = ast.Import{ - source_name: source_name + source_name: src_name pos: import_pos.extend(pos) mod_pos: pos alias_pos: submod_pos - mod: util.qualify_import(p.pref, source_name, p.file_path) + mod: util.qualify_import(p.pref, src_name, p.file_path) alias: mod_alias } } if mod_name_arr.len == 1 { import_node = ast.Import{ - source_name: source_name + source_name: src_name pos: import_node.pos mod_pos: import_node.mod_pos alias_pos: import_node.alias_pos @@ -277,7 +277,7 @@ fn (mut p Parser) import_stmt() ast.Import { return import_node } import_node = ast.Import{ - source_name: source_name + source_name: src_name pos: import_node.pos.extend(alias_pos) mod_pos: import_node.mod_pos alias_pos: alias_pos @@ -291,7 +291,7 @@ fn (mut p Parser) import_stmt() ast.Import { initial_syms_pos = initial_syms_pos.extend(p.tok.pos()) import_node = ast.Import{ ...import_node - source_name: source_name + source_name: src_name syms_pos: initial_syms_pos pos: import_node.pos.extend(initial_syms_pos) } diff --git a/vlib/v/tests/interfaces/interface_to_ptr_interface_as_cast_test.v b/vlib/v/tests/interfaces/interface_to_ptr_interface_as_cast_test.v index 94dec4eb3..1e2ce46b8 100644 --- a/vlib/v/tests/interfaces/interface_to_ptr_interface_as_cast_test.v +++ b/vlib/v/tests/interfaces/interface_to_ptr_interface_as_cast_test.v @@ -41,6 +41,8 @@ fn iface_to_ptr_iface(c DbConn) string { } fn test_iface_as_ptr_iface() { - c := DbConn(PgConn{ tag: 'pg' }) + c := DbConn(PgConn{ + tag: 'pg' + }) assert iface_to_ptr_iface(c) == 'ok' } diff --git a/vlib/v/tests/shared_library_boehm_register_threads_test.v b/vlib/v/tests/shared_library_boehm_register_threads_test.v index f283fc757..9997074b1 100644 --- a/vlib/v/tests/shared_library_boehm_register_threads_test.v +++ b/vlib/v/tests/shared_library_boehm_register_threads_test.v @@ -24,7 +24,8 @@ fn test_shared_library_boehm_emits_allow_register_threads() { '\treturn 1', '}', ].join('\n')) or { panic(err) } - res := os.execute('${os.quoted_path(vexe)} -gc boehm -shared -o ${os.quoted_path(lib_c)} ${os.quoted_path(lib_src)}') + res := + os.execute('${os.quoted_path(vexe)} -gc boehm -shared -o ${os.quoted_path(lib_c)} ${os.quoted_path(lib_src)}') assert res.exit_code == 0, 'shared-lib codegen failed:\n${res.output}' c_src := os.read_file(lib_c) or { panic(err) } // The call must appear inside `_vinit`, not in a separate constructor: -- 2.39.5