mirror of
https://github.com/vlang/v.git
synced 2025-09-13 22:42:26 +03:00
fix
This commit is contained in:
parent
b502d52280
commit
59a88c8486
2 changed files with 27 additions and 1 deletions
|
@ -851,7 +851,10 @@ or use an explicit `unsafe{ a[..] }`, if you do not want a copy of the slice.',
|
||||||
if mut init_field.expr is ast.CallExpr
|
if mut init_field.expr is ast.CallExpr
|
||||||
&& init_field.expr.return_type.has_flag(.generic) {
|
&& init_field.expr.return_type.has_flag(.generic) {
|
||||||
expected_type := c.unwrap_generic(init_field.expected_type)
|
expected_type := c.unwrap_generic(init_field.expected_type)
|
||||||
got_type_ret := c.unwrap_generic(init_field.expr.return_type)
|
mut got_type_ret := c.unwrap_generic(init_field.expr.return_type)
|
||||||
|
if init_field.expr.or_block.kind != .absent {
|
||||||
|
got_type_ret = got_type_ret.clear_option_and_result()
|
||||||
|
}
|
||||||
if expected_type != got_type_ret {
|
if expected_type != got_type_ret {
|
||||||
c.error('cannot assign `${c.table.type_to_str(got_type_ret)}` to struct field `${init_field.name}` with type `${c.table.type_to_str(expected_type)}`',
|
c.error('cannot assign `${c.table.type_to_str(got_type_ret)}` to struct field `${init_field.name}` with type `${c.table.type_to_str(expected_type)}`',
|
||||||
init_field.expr.pos)
|
init_field.expr.pos)
|
||||||
|
|
23
vlib/v/tests/generics/generic_struct_field_unwrap_test.v
Normal file
23
vlib/v/tests/generics/generic_struct_field_unwrap_test.v
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
struct Test[T] {
|
||||||
|
pub:
|
||||||
|
value T
|
||||||
|
}
|
||||||
|
|
||||||
|
struct AuxTest[T] {
|
||||||
|
pub:
|
||||||
|
any_value Test[T]
|
||||||
|
}
|
||||||
|
|
||||||
|
fn decode[T](arg Test[T]) !Test[T] {
|
||||||
|
return Test[T]{}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn initializing[T]() !AuxTest[T] {
|
||||||
|
return AuxTest[T]{
|
||||||
|
any_value: decode[T](Test[T]{})!
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn test_main() {
|
||||||
|
dump(initializing[int]()!)
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue