1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

checker: fix fn call with generic []T arg (#16781)

This commit is contained in:
Felipe Pena 2022-12-28 06:05:11 -03:00 committed by GitHub
parent b171102b03
commit 0f37ff197b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 2 deletions

View File

@ -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

View File

@ -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
}