mirror of
https://github.com/vlang/v.git
synced 2025-09-18 03:46:36 -04:00
This commit is contained in:
parent
70112d84a9
commit
1a9dab29c6
@ -1719,7 +1719,15 @@ fn (mut c Checker) fn_call(mut node ast.CallExpr, mut continue_check &bool) ast.
|
|||||||
} else {
|
} else {
|
||||||
func.params[i]
|
func.params[i]
|
||||||
}
|
}
|
||||||
|
if param.typ.has_flag(.generic) {
|
||||||
|
if unwrap_typ := c.table.convert_generic_type(param.typ, func.generic_names,
|
||||||
|
concrete_types)
|
||||||
|
{
|
||||||
|
c.expected_type = unwrap_typ
|
||||||
|
}
|
||||||
|
} else {
|
||||||
c.expected_type = param.typ
|
c.expected_type = param.typ
|
||||||
|
}
|
||||||
already_checked := node.language != .js && call_arg.expr is ast.CallExpr
|
already_checked := node.language != .js && call_arg.expr is ast.CallExpr
|
||||||
typ := c.check_expr_option_or_result_call(call_arg.expr, if already_checked
|
typ := c.check_expr_option_or_result_call(call_arg.expr, if already_checked
|
||||||
&& mut call_arg.expr is ast.CallExpr {
|
&& mut call_arg.expr is ast.CallExpr {
|
||||||
|
29
vlib/v/tests/generics/generics_with_empty_array_arg_test.v
Normal file
29
vlib/v/tests/generics/generics_with_empty_array_arg_test.v
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
fn count_str(array []string) int {
|
||||||
|
return array.len
|
||||||
|
}
|
||||||
|
|
||||||
|
fn count_int(array []int) int {
|
||||||
|
return array.len
|
||||||
|
}
|
||||||
|
|
||||||
|
fn count[T](array []T) int {
|
||||||
|
return array.len
|
||||||
|
}
|
||||||
|
|
||||||
|
fn test_generics_with_empty_array_arg() {
|
||||||
|
assert count_str(['one', 'two']) == 2
|
||||||
|
assert count_str([]string{}) == 0
|
||||||
|
assert count_str([]) == 0
|
||||||
|
|
||||||
|
assert count_int([1, 2]) == 2
|
||||||
|
assert count_int([]int{}) == 0
|
||||||
|
assert count_int([]) == 0
|
||||||
|
|
||||||
|
assert count[f64]([1.0, 2.0]) == 2
|
||||||
|
assert count[f64]([]f64{}) == 0
|
||||||
|
assert count[f64]([]) == 0
|
||||||
|
|
||||||
|
assert count[int]([1, 2]) == 2
|
||||||
|
assert count[int]([]int{}) == 0
|
||||||
|
assert count[int]([]) == 0
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user