From a7fef7c4930a3443b41f2a53c855839df4cccea6 Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Wed, 27 May 2026 04:49:24 +0300 Subject: [PATCH] all: fix more fn shadowing warnings --- vlib/rand/cuid2/cuid2.v | 6 +++--- vlib/v/checker/tests/ambiguous_function_call.out | 7 +++++++ vlib/v/checker/tests/clash_ident_module_name_prefix.out | 7 +++++++ .../tests/generics_fn_called_variadic_arg_mismatch.vv | 8 ++++---- vlib/v/checker/tests/nocopy_struct_err.out | 8 ++++---- vlib/v/checker/tests/nocopy_struct_err.vv | 4 ++-- vlib/v/checker/tests/opt_is_op_check_err.out | 2 +- vlib/v/checker/tests/opt_is_op_check_err.vv | 4 ++-- 8 files changed, 30 insertions(+), 16 deletions(-) diff --git a/vlib/rand/cuid2/cuid2.v b/vlib/rand/cuid2/cuid2.v index a2eb79ef2..cebe1518b 100644 --- a/vlib/rand/cuid2/cuid2.v +++ b/vlib/rand/cuid2/cuid2.v @@ -132,9 +132,9 @@ fn create_fingerprint(mut prng rand.PRNG, env_key_string string) string { } fn hash(input string) string { - mut hash := sha3.new512() or { panic(err) } - hash.write(input.bytes()) or { panic(err) } - hash_digest := hash.checksum() + mut h := sha3.new512() or { panic(err) } + h.write(input.bytes()) or { panic(err) } + hash_digest := h.checksum() // Drop the first character because it will bias // the histogram to the left. diff --git a/vlib/v/checker/tests/ambiguous_function_call.out b/vlib/v/checker/tests/ambiguous_function_call.out index 0a087ad3d..c58407ec4 100644 --- a/vlib/v/checker/tests/ambiguous_function_call.out +++ b/vlib/v/checker/tests/ambiguous_function_call.out @@ -1,3 +1,10 @@ +vlib/v/checker/tests/ambiguous_function_call.vv:6:2: warning: variable `foo2` shadows a function declaration + 4 | + 5 | fn foo2() { + 6 | foo2 := 1 + | ~~~~ + 7 | foo2(foo2) + 8 | } vlib/v/checker/tests/ambiguous_function_call.vv:2:2: error: ambiguous call to: `foo1`, may refer to fn `foo1` or variable `foo1` 1 | fn foo1(foo1 int) { 2 | foo1(foo1 + 1) diff --git a/vlib/v/checker/tests/clash_ident_module_name_prefix.out b/vlib/v/checker/tests/clash_ident_module_name_prefix.out index d7374af50..d0cbe5ce3 100644 --- a/vlib/v/checker/tests/clash_ident_module_name_prefix.out +++ b/vlib/v/checker/tests/clash_ident_module_name_prefix.out @@ -1,3 +1,10 @@ +vlib/v/checker/tests/clash_ident_module_name_prefix.vv:17:2: warning: variable `builtin__string_str` shadows a function declaration + 15 | + 16 | fn main() { + 17 | builtin__string_str := 'Hello V!'.str() + | ~~~~~~~~~~~~~~~~~~~ + 18 | time__now := time.now() + 19 | os__log := 'Hello V!' vlib/v/checker/tests/clash_ident_module_name_prefix.vv:7:1: error: identifier cannot use prefix `builtin__` of imported module `builtin` 5 | // os is not imported so the os__ prefix should not produce an error 6 | diff --git a/vlib/v/checker/tests/generics_fn_called_variadic_arg_mismatch.vv b/vlib/v/checker/tests/generics_fn_called_variadic_arg_mismatch.vv index a35ec663f..5ca20b7a2 100644 --- a/vlib/v/checker/tests/generics_fn_called_variadic_arg_mismatch.vv +++ b/vlib/v/checker/tests/generics_fn_called_variadic_arg_mismatch.vv @@ -1,11 +1,11 @@ fn max[T](a ...T) T { - mut max := a[0] + mut result := a[0] for item in a[1..] { - if max < item { - max = item + if result < item { + result = item } } - return max + return result } fn main() { diff --git a/vlib/v/checker/tests/nocopy_struct_err.out b/vlib/v/checker/tests/nocopy_struct_err.out index 3fa5ef741..cceaf2f80 100644 --- a/vlib/v/checker/tests/nocopy_struct_err.out +++ b/vlib/v/checker/tests/nocopy_struct_err.out @@ -5,16 +5,16 @@ vlib/v/checker/tests/nocopy_struct_err.vv:11:19: error: cannot copy @[nocopy] st | ~~~~~~~~~~~~~ 12 | } 13 | -vlib/v/checker/tests/nocopy_struct_err.vv:22:10: error: cannot copy @[nocopy] struct: use a reference instead +vlib/v/checker/tests/nocopy_struct_err.vv:22:9: error: cannot copy @[nocopy] struct: use a reference instead 20 | handle: 2 21 | } - 22 | copy := resource - | ~~~~~~~~ + 22 | dup := resource + | ~~~~~~~~ 23 | takes_value(resource) 24 | _ = Holder{ vlib/v/checker/tests/nocopy_struct_err.vv:23:14: error: cannot pass @[nocopy] struct by value: use a reference instead 21 | } - 22 | copy := resource + 22 | dup := resource 23 | takes_value(resource) | ~~~~~~~~ 24 | _ = Holder{ diff --git a/vlib/v/checker/tests/nocopy_struct_err.vv b/vlib/v/checker/tests/nocopy_struct_err.vv index f898b54cc..dfa47362b 100644 --- a/vlib/v/checker/tests/nocopy_struct_err.vv +++ b/vlib/v/checker/tests/nocopy_struct_err.vv @@ -19,7 +19,7 @@ fn main() { mut resource := Resource{ handle: 2 } - copy := resource + dup := resource takes_value(resource) _ = Holder{ field: resource @@ -30,5 +30,5 @@ fn main() { _ = fn [mut resource] () { _ = resource.handle } - _ = copy + _ = dup } diff --git a/vlib/v/checker/tests/opt_is_op_check_err.out b/vlib/v/checker/tests/opt_is_op_check_err.out index c31d80c53..ecf75621a 100644 --- a/vlib/v/checker/tests/opt_is_op_check_err.out +++ b/vlib/v/checker/tests/opt_is_op_check_err.out @@ -4,7 +4,7 @@ vlib/v/checker/tests/opt_is_op_check_err.vv:7:6: notice: unused parameter: `a` 7 | fn r(a string) {} | ^ 8 | - 9 | fn t(s ?Foo) { + 9 | fn process(s ?Foo) { vlib/v/checker/tests/opt_is_op_check_err.vv:13:7: error: t.a is an Optional, it needs to be unwrapped first 11 | a: s 12 | } diff --git a/vlib/v/checker/tests/opt_is_op_check_err.vv b/vlib/v/checker/tests/opt_is_op_check_err.vv index 917bdacba..43961f9fc 100644 --- a/vlib/v/checker/tests/opt_is_op_check_err.vv +++ b/vlib/v/checker/tests/opt_is_op_check_err.vv @@ -6,7 +6,7 @@ struct Struct { fn r(a string) {} -fn t(s ?Foo) { +fn process(s ?Foo) { mut t := Struct{ a: s } @@ -17,5 +17,5 @@ fn t(s ?Foo) { fn main() { s := ?Foo('hello') - t(s) + process(s) } -- 2.39.5