mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
This commit is contained in:
parent
7ddf569de6
commit
21d1f86ead
@ -1457,7 +1457,7 @@ fn (mut c Checker) check_return_generics_struct(return_type ast.Type, mut call_e
|
|||||||
idx := c.table.type_idxs[nrt]
|
idx := c.table.type_idxs[nrt]
|
||||||
if idx != 0 {
|
if idx != 0 {
|
||||||
c.ensure_type_exists(idx, call_expr.pos) or {}
|
c.ensure_type_exists(idx, call_expr.pos) or {}
|
||||||
call_expr.return_type = ast.new_type(idx).derive(return_type)
|
call_expr.return_type = ast.new_type(idx).derive(return_type).clear_flag(.generic)
|
||||||
} else {
|
} else {
|
||||||
mut fields := rts.info.fields.clone()
|
mut fields := rts.info.fields.clone()
|
||||||
if rts.info.generic_types.len == concrete_types.len {
|
if rts.info.generic_types.len == concrete_types.len {
|
||||||
@ -1481,7 +1481,7 @@ fn (mut c Checker) check_return_generics_struct(return_type ast.Type, mut call_e
|
|||||||
mod: c.mod
|
mod: c.mod
|
||||||
info: info
|
info: info
|
||||||
})
|
})
|
||||||
call_expr.return_type = ast.new_type(stru_idx)
|
call_expr.return_type = ast.new_type(stru_idx).derive(return_type).clear_flag(.generic)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,15 @@
|
|||||||
|
struct Foo<T> {
|
||||||
|
data []T
|
||||||
|
}
|
||||||
|
|
||||||
|
fn new_foo<T>(len int) &Foo<T> {
|
||||||
|
return &Foo{
|
||||||
|
data: []T{len: len}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn test_generics_return_reference_generics_struct() {
|
||||||
|
f := new_foo<int>(4)
|
||||||
|
println(f)
|
||||||
|
assert f.data == [0, 0, 0, 0]
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user