mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
This commit is contained in:
parent
c0f855ace7
commit
21512d1491
@ -550,7 +550,7 @@ pub fn (mut c Checker) infer_fn_generic_types(f ast.Fn, mut call_expr ast.CallEx
|
||||
if to_set.has_flag(.generic) {
|
||||
to_set = c.unwrap_generic(to_set)
|
||||
}
|
||||
} else {
|
||||
} else if param.typ.has_flag(.generic) {
|
||||
arg_sym := c.table.get_type_symbol(arg.typ)
|
||||
if arg_sym.kind == .array && param_type_sym.kind == .array {
|
||||
mut arg_elem_info := arg_sym.info as ast.Array
|
||||
@ -588,7 +588,7 @@ pub fn (mut c Checker) infer_fn_generic_types(f ast.Fn, mut call_expr ast.CallEx
|
||||
}
|
||||
} else if param.typ.has_flag(.variadic) {
|
||||
to_set = c.table.mktyp(arg.typ)
|
||||
} else if arg_sym.kind == .struct_ && param.typ.has_flag(.generic) {
|
||||
} else if arg_sym.kind == .struct_ {
|
||||
info := arg_sym.info as ast.Struct
|
||||
generic_names := info.generic_types.map(c.table.get_type_symbol(it).name)
|
||||
if gt_name in generic_names && info.generic_types.len == info.concrete_types.len {
|
||||
|
36
vlib/v/tests/generic_fn_infer_multi_paras_test.v
Normal file
36
vlib/v/tests/generic_fn_infer_multi_paras_test.v
Normal file
@ -0,0 +1,36 @@
|
||||
pub struct Page {
|
||||
pub mut:
|
||||
lang string
|
||||
page string
|
||||
var_one string
|
||||
var_two string
|
||||
}
|
||||
|
||||
fn get_keys_and_values<T>(mut keys []string, mut values []string, mut data T) {
|
||||
$for field in T.fields {
|
||||
$if field.typ is string {
|
||||
keys << field.name
|
||||
values << data.$(field.name)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn awesome<T>(mut data T) {
|
||||
mut keys := []string{}
|
||||
mut values := []string{}
|
||||
get_keys_and_values(mut keys, mut values, mut data)
|
||||
println(keys)
|
||||
assert keys == ['lang', 'page', 'var_one', 'var_two']
|
||||
println(values)
|
||||
assert values == ['vlang', 'one', 'variable one', 'variable two']
|
||||
}
|
||||
|
||||
fn test_generic_fn_infer_multi_paras() {
|
||||
mut page := Page{
|
||||
lang: 'vlang'
|
||||
page: 'one'
|
||||
var_one: 'variable one'
|
||||
var_two: 'variable two'
|
||||
}
|
||||
awesome(mut page)
|
||||
}
|
Loading…
Reference in New Issue
Block a user