mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
parent
a2eb686506
commit
246c09db96
@ -443,6 +443,9 @@ pub fn (mut c Checker) infer_fn_types(f table.Fn, mut call_expr ast.CallExpr) {
|
||||
param_type_sym := c.table.get_type_symbol(param.typ)
|
||||
if param.typ.has_flag(.generic) && param_type_sym.name == gt_name {
|
||||
typ = c.table.mktyp(arg.typ)
|
||||
if arg.expr.is_auto_deref_var() {
|
||||
typ = typ.deref()
|
||||
}
|
||||
break
|
||||
}
|
||||
arg_sym := c.table.get_type_symbol(arg.typ)
|
||||
|
@ -1018,6 +1018,10 @@ fn (mut g Gen) call_args(node ast.CallExpr) {
|
||||
g.write('/*af arg*/' + name)
|
||||
}
|
||||
} else {
|
||||
if node.generic_types.len > 0 && arg.expr.is_auto_deref_var() && !arg.is_mut
|
||||
&& !expected_types[i].is_ptr() {
|
||||
g.write('*')
|
||||
}
|
||||
g.ref_or_deref_arg(arg, expected_types[i], node.language)
|
||||
}
|
||||
} else {
|
||||
|
27
vlib/v/tests/generics_in_big_struct_method_test.v
Normal file
27
vlib/v/tests/generics_in_big_struct_method_test.v
Normal file
@ -0,0 +1,27 @@
|
||||
struct Product {
|
||||
pub mut:
|
||||
id int = 2
|
||||
sku string = 'ABCD'
|
||||
ean13 string = 'EFGH'
|
||||
|
||||
collections string
|
||||
ptype string
|
||||
featured_image string
|
||||
featured_media string
|
||||
handle string
|
||||
variant int
|
||||
}
|
||||
|
||||
pub fn (p Product) save() string {
|
||||
return do_something(p)
|
||||
}
|
||||
|
||||
fn do_something<T>(p T) string {
|
||||
return 'whatever'
|
||||
}
|
||||
|
||||
fn test_generics_in_big_struct_method() {
|
||||
mut p := Product{}
|
||||
println(p.save())
|
||||
assert p.save() == 'whatever'
|
||||
}
|
Loading…
Reference in New Issue
Block a user