1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

ast: fix inferring generic struct (fix #16830) (#16831)

This commit is contained in:
yuyi 2023-01-01 23:36:18 +08:00 committed by GitHub
parent 51bb630ea4
commit 9d49b69b69
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 30 additions and 0 deletions

View File

@ -1975,6 +1975,7 @@ pub fn (mut t Table) unwrap_generic_type(typ Type, generic_names []string, concr
cname: util.no_dots(c_nrt)
mod: ts.mod
info: info
is_pub: ts.is_pub
)
for typ_ in needs_unwrap_types {
t.unwrap_generic_type(typ_, generic_names, concrete_types)
@ -2010,6 +2011,7 @@ pub fn (mut t Table) unwrap_generic_type(typ Type, generic_names []string, concr
cname: util.no_dots(c_nrt)
mod: ts.mod
info: info
is_pub: ts.is_pub
)
for typ_ in needs_unwrap_types {
t.unwrap_generic_type(typ_, generic_names, concrete_types)
@ -2053,6 +2055,7 @@ pub fn (mut t Table) unwrap_generic_type(typ Type, generic_names []string, concr
cname: util.no_dots(c_nrt)
mod: ts.mod
info: info
is_pub: ts.is_pub
)
mut ts_copy := t.sym(new_idx)
for method in all_methods {

View File

@ -0,0 +1,9 @@
import v.tests.generics_from_modules.newmodule as nm
fn test_infer_generic_struct() {
a_in := [int(1), 2, 4]
res := nm.take_input(a: a_in, b: 3, c: int(5))
println(res)
assert res == [f32(1.0), 2.0, 4.0, 3.0, 5.0]
}

View File

@ -0,0 +1,18 @@
module newmodule
pub struct Params[T] {
mut:
a []T
b int
c T
}
pub fn take_input[T](p Params[T]) []f32 {
mut res := []f32{}
for x in p.a {
res << f32(x)
}
res << f32(p.b)
res << f32(p.c)
return res
}