diff --git a/vlib/v/checker/fn.v b/vlib/v/checker/fn.v index 950a3c21bb0857..92a27035e0c2ea 100644 --- a/vlib/v/checker/fn.v +++ b/vlib/v/checker/fn.v @@ -1992,7 +1992,12 @@ fn (mut c Checker) resolve_comptime_args(func &ast.Fn, node_ ast.CallExpr, concr } } } else if call_arg.expr.obj.ct_type_var == .generic_var { - mut ctyp := c.type_resolver.get_type(call_arg.expr) + mut ctyp := c.unwrap_generic(c.type_resolver.get_type(call_arg.expr)) + cparam_type_sym := c.table.sym(c.unwrap_generic(ctyp)) + param_typ_sym := c.table.sym(param_typ) + if param_typ_sym.kind == .array && cparam_type_sym.info is ast.Array { + ctyp = cparam_type_sym.info.elem_type + } if node_.args[i].expr.is_auto_deref_var() { ctyp = ctyp.deref() } diff --git a/vlib/v/tests/generics/generic_fn_array_infer_var_test.v b/vlib/v/tests/generics/generic_fn_array_infer_var_test.v new file mode 100644 index 00000000000000..cb30e0ba08ac71 --- /dev/null +++ b/vlib/v/tests/generics/generic_fn_array_infer_var_test.v @@ -0,0 +1,20 @@ +fn function_that_receives_an_array_of_generic_type[T](array []T) { + assert array.len == 0 +} + +fn function_that_returns_an_array_of_generic_type[T]() []T { + return [] +} + +fn func[T]() { + res := function_that_returns_an_array_of_generic_type[T]() + function_that_receives_an_array_of_generic_type(res) + assert res.len == 0 + function_that_receives_an_array_of_generic_type[T](res) +} + +fn test_main() { + func[string]() + func[int]() + func[f64]() +}