From 0f37ff197b5d8c440fd2b73066dd48334652e200 Mon Sep 17 00:00:00 2001 From: Felipe Pena Date: Wed, 28 Dec 2022 06:05:11 -0300 Subject: [PATCH] checker: fix fn call with generic []T arg (#16781) --- vlib/v/checker/check_types.v | 4 ++-- vlib/v/tests/fn_call_generic_array_arg_test.v | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) create mode 100644 vlib/v/tests/fn_call_generic_array_arg_test.v diff --git a/vlib/v/checker/check_types.v b/vlib/v/checker/check_types.v index 8b542ce15d..16658ac267 100644 --- a/vlib/v/checker/check_types.v +++ b/vlib/v/checker/check_types.v @@ -263,8 +263,8 @@ fn (mut c Checker) check_expected_call_arg(got ast.Type, expected_ ast.Type, lan return } } else { - got_typ_sym := c.table.sym(got) - expected_typ_sym := c.table.sym(expected_) + got_typ_sym := c.table.sym(c.unwrap_generic(got)) + expected_typ_sym := c.table.sym(c.unwrap_generic(expected_)) // Check on Generics types, there are some case where we have the following case // `&Type[int] == &Type[]`. This is a common case we are implementing a function diff --git a/vlib/v/tests/fn_call_generic_array_arg_test.v b/vlib/v/tests/fn_call_generic_array_arg_test.v new file mode 100644 index 0000000000..ea76c89a8f --- /dev/null +++ b/vlib/v/tests/fn_call_generic_array_arg_test.v @@ -0,0 +1,15 @@ +fn f64_fun(x []f64) f64 { + return x[0] + x[1] +} + +fn t_fun[T](x []T) T { + $if T is f64 { + return f64_fun(x) + } $else { + return T(0) + } +} + +fn test_main() { + assert t_fun([1.0, 2.0]) == 3.0 +}