From b0b4b8e65bbbf0cfaf2e8680a3e98e7b66f25c48 Mon Sep 17 00:00:00 2001 From: yuyi Date: Mon, 5 Jul 2021 00:15:15 +0800 Subject: [PATCH] checker: fix missing check generic fn call args (fix #10649) (#10657) --- cmd/tools/vdoc/vdoc.v | 2 +- vlib/v/checker/checker.v | 2 +- .../tests/generic_fn_decl_without_generic_names_err.out | 7 ------- .../tests/generics_fn_called_multi_args_mismatch.out | 7 +++++++ .../tests/generics_fn_called_multi_args_mismatch.vv | 7 +++++++ vlib/v/compiler_errors_test.v | 4 ++-- 6 files changed, 18 insertions(+), 11 deletions(-) create mode 100644 vlib/v/checker/tests/generics_fn_called_multi_args_mismatch.out create mode 100644 vlib/v/checker/tests/generics_fn_called_multi_args_mismatch.vv diff --git a/cmd/tools/vdoc/vdoc.v b/cmd/tools/vdoc/vdoc.v index 1fe0d3f803..f4f0264600 100644 --- a/cmd/tools/vdoc/vdoc.v +++ b/cmd/tools/vdoc/vdoc.v @@ -178,7 +178,7 @@ fn (vd VDoc) work_processor(mut work sync.Channel, mut wg sync.WaitGroup) { fn (vd VDoc) render_parallel(out Output) { vjobs := runtime.nr_jobs() - mut work := sync.new_channel(vd.docs.len) + mut work := sync.new_channel(u32(vd.docs.len)) mut wg := sync.new_waitgroup() for i in 0 .. vd.docs.len { p_doc := ParallelDoc{vd.docs[i], out} diff --git a/vlib/v/checker/checker.v b/vlib/v/checker/checker.v index d0eaa3e0f8..492753d780 100644 --- a/vlib/v/checker/checker.v +++ b/vlib/v/checker/checker.v @@ -2658,7 +2658,7 @@ pub fn (mut c Checker) fn_call(mut call_expr ast.CallExpr) ast.Type { if typ_sym.kind == .void && param_typ_sym.kind == .string { continue } - if func.generic_names.len > 0 { + if param.typ.has_flag(.generic) { continue } if c.pref.translated { diff --git a/vlib/v/checker/tests/generic_fn_decl_without_generic_names_err.out b/vlib/v/checker/tests/generic_fn_decl_without_generic_names_err.out index 9ef31efbc2..3453697965 100644 --- a/vlib/v/checker/tests/generic_fn_decl_without_generic_names_err.out +++ b/vlib/v/checker/tests/generic_fn_decl_without_generic_names_err.out @@ -12,13 +12,6 @@ vlib/v/checker/tests/generic_fn_decl_without_generic_names_err.vv:27:7: error: < | ~~ 28 | handle(t) 29 | // println("${t.msg}") -vlib/v/checker/tests/generic_fn_decl_without_generic_names_err.vv:28:9: error: cannot use `void` as `T` in argument 1 to `handle` - 26 | fn g_worker(g Generic) { - 27 | t := <-g.ch - 28 | handle(t) - | ^ - 29 | // println("${t.msg}") - 30 | } vlib/v/checker/tests/generic_fn_decl_without_generic_names_err.vv:32:1: error: generic function declaration must specify generic type names, e.g. foo 30 | } 31 | diff --git a/vlib/v/checker/tests/generics_fn_called_multi_args_mismatch.out b/vlib/v/checker/tests/generics_fn_called_multi_args_mismatch.out new file mode 100644 index 0000000000..30d630df2e --- /dev/null +++ b/vlib/v/checker/tests/generics_fn_called_multi_args_mismatch.out @@ -0,0 +1,7 @@ +vlib/v/checker/tests/generics_fn_called_multi_args_mismatch.vv:3:13: error: cannot use `[]rune` as `string` in argument 2 to `foo_str` + 1 | fn main() { + 2 | x := 'ab'.runes()[..1] + 3 | foo_str(1, x) + | ^ + 4 | } + 5 | diff --git a/vlib/v/checker/tests/generics_fn_called_multi_args_mismatch.vv b/vlib/v/checker/tests/generics_fn_called_multi_args_mismatch.vv new file mode 100644 index 0000000000..4062162655 --- /dev/null +++ b/vlib/v/checker/tests/generics_fn_called_multi_args_mismatch.vv @@ -0,0 +1,7 @@ +fn main() { + x := 'ab'.runes()[..1] + foo_str(1, x) +} + +fn foo_str(b T, a string) { +} diff --git a/vlib/v/compiler_errors_test.v b/vlib/v/compiler_errors_test.v index 706a411bfa..13c1c9ffae 100644 --- a/vlib/v/compiler_errors_test.v +++ b/vlib/v/compiler_errors_test.v @@ -174,8 +174,8 @@ fn (mut tasks Tasks) run() { vjobs := if tasks.parallel_jobs > 0 { tasks.parallel_jobs } else { runtime.nr_jobs() } mut bench := benchmark.new_benchmark() bench.set_total_expected_steps(tasks.all.len) - mut work := sync.new_channel(tasks.all.len) - mut results := sync.new_channel(tasks.all.len) + mut work := sync.new_channel(u32(tasks.all.len)) + mut results := sync.new_channel(u32(tasks.all.len)) mut m_skip_files := skip_files.clone() if os.getenv('V_CI_UBUNTU_MUSL').len > 0 { m_skip_files << skip_on_ubuntu_musl