mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
This commit is contained in:
@@ -934,9 +934,14 @@ fn (mut c Checker) infer_fn_generic_types(func ast.Fn, mut node ast.CallExpr) {
|
|||||||
typ = typ.set_nr_muls(0)
|
typ = typ.set_nr_muls(0)
|
||||||
}
|
}
|
||||||
} else if param.typ.has_flag(.generic) {
|
} else if param.typ.has_flag(.generic) {
|
||||||
arg_sym := c.table.final_sym(arg.typ)
|
arg_typ := if c.table.sym(arg.typ).kind == .any {
|
||||||
|
c.unwrap_generic(arg.typ)
|
||||||
|
} else {
|
||||||
|
arg.typ
|
||||||
|
}
|
||||||
|
arg_sym := c.table.final_sym(arg_typ)
|
||||||
if param.typ.has_flag(.variadic) {
|
if param.typ.has_flag(.variadic) {
|
||||||
typ = ast.mktyp(arg.typ)
|
typ = ast.mktyp(arg_typ)
|
||||||
} else if arg_sym.info is ast.Array && param_sym.info is ast.Array {
|
} else if arg_sym.info is ast.Array && param_sym.info is ast.Array {
|
||||||
mut arg_elem_typ, mut param_elem_typ := arg_sym.info.elem_type, param_sym.info.elem_type
|
mut arg_elem_typ, mut param_elem_typ := arg_sym.info.elem_type, param_sym.info.elem_type
|
||||||
mut arg_elem_sym, mut param_elem_sym := c.table.sym(arg_elem_typ), c.table.sym(param_elem_typ)
|
mut arg_elem_sym, mut param_elem_sym := c.table.sym(arg_elem_typ), c.table.sym(param_elem_typ)
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
fn make_2x3[T](mut res [][]T) ! {
|
fn make_2x3[T](mut res [][]T) ! {
|
||||||
mut a := []T{len: 6}
|
mut a := []T{len: 6}
|
||||||
res = reshape(a, [2, 3])!
|
res = reshape[T](a, [2, 3])!
|
||||||
}
|
}
|
||||||
|
|
||||||
fn reshape[T](y []T, dims []int) ![][]T {
|
fn reshape[T](y []T, dims []int) ![][]T {
|
||||||
|
17
vlib/v/tests/infer_generic_array_type_in_nested_call_test.v
Normal file
17
vlib/v/tests/infer_generic_array_type_in_nested_call_test.v
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
fn unmarshal_any[T]() T {
|
||||||
|
mut typ := T{}
|
||||||
|
$if T is $array {
|
||||||
|
unmarshal_array(mut typ)
|
||||||
|
}
|
||||||
|
return typ
|
||||||
|
}
|
||||||
|
|
||||||
|
fn unmarshal_array[T](mut typ []T) {
|
||||||
|
typ << 42
|
||||||
|
}
|
||||||
|
|
||||||
|
fn test_infer_generic_array_type_in_nested_call() {
|
||||||
|
ret := unmarshal_any[[]int]()
|
||||||
|
println(ret)
|
||||||
|
assert ret == [42]
|
||||||
|
}
|
Reference in New Issue
Block a user