From c4b5805890b5817d4f696567e6d1b207d6263485 Mon Sep 17 00:00:00 2001 From: yuyi Date: Mon, 5 Jul 2021 15:14:00 +0800 Subject: [PATCH] checker: check generic method call args mismatch (#10669) --- vlib/os/file_test.v | 10 +++++----- vlib/v/checker/checker.v | 2 +- .../tests/generics_fn_called_multi_args_mismatch.out | 11 +++++++++-- .../tests/generics_fn_called_multi_args_mismatch.vv | 10 ++++++++++ 4 files changed, 25 insertions(+), 8 deletions(-) diff --git a/vlib/os/file_test.v b/vlib/os/file_test.v index 6144ad1aa1..493dc1220a 100644 --- a/vlib/os/file_test.v +++ b/vlib/os/file_test.v @@ -306,15 +306,15 @@ fn test_read_raw_at() ? { f.write_raw(another_permission) ? f.close() f = os.open_file(tfile, 'r') ? - mut at := 3 + mut at := u64(3) p := f.read_raw_at(at) ? - at += int(sizeof(Point)) + at += sizeof(Point) b := f.read_raw_at(at) ? - at += int(sizeof(byte)) + at += sizeof(byte) c := f.read_raw_at(at) ? - at += int(sizeof(Color)) + at += sizeof(Color) x := f.read_raw_at(at) ? - at += int(sizeof(Permissions)) + at += sizeof(Permissions) f.close() assert p == another_point diff --git a/vlib/v/checker/checker.v b/vlib/v/checker/checker.v index b93f082d6e..72750abd8f 100644 --- a/vlib/v/checker/checker.v +++ b/vlib/v/checker/checker.v @@ -2038,7 +2038,7 @@ pub fn (mut c Checker) method_call(mut call_expr ast.CallExpr) ast.Type { } continue } - if method.generic_names.len > 0 { + if exp_arg_typ.has_flag(.generic) { continue } c.check_expected_call_arg(got_arg_typ, c.unwrap_generic(exp_arg_typ), call_expr.language) or { 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 index 30d630df2e..3f23d6b4c8 100644 --- a/vlib/v/checker/tests/generics_fn_called_multi_args_mismatch.out +++ b/vlib/v/checker/tests/generics_fn_called_multi_args_mismatch.out @@ -3,5 +3,12 @@ vlib/v/checker/tests/generics_fn_called_multi_args_mismatch.vv:3:13: error: cann 2 | x := 'ab'.runes()[..1] 3 | foo_str(1, x) | ^ - 4 | } - 5 | + 4 | + 5 | foo := Foo{} +vlib/v/checker/tests/generics_fn_called_multi_args_mismatch.vv:6:11: error: cannot use `[]rune` as `string` in argument 1 to `Foo.info` + 4 | + 5 | foo := Foo{} + 6 | foo.info(x) + | ^ + 7 | } + 8 | 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 index 4062162655..fdbdf4d15a 100644 --- a/vlib/v/checker/tests/generics_fn_called_multi_args_mismatch.vv +++ b/vlib/v/checker/tests/generics_fn_called_multi_args_mismatch.vv @@ -1,7 +1,17 @@ fn main() { x := 'ab'.runes()[..1] foo_str(1, x) + + foo := Foo{} + foo.info(x) } fn foo_str(b T, a string) { } + +struct Foo { + t T +} + +fn (f Foo) info(a string) { +}