Skip to content

Commit aa7de61

Browse files
authored
checker: fix checking return type call disregarding unwrapping (fix #25140) (#25143)
1 parent 98ca0f0 commit aa7de61

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

vlib/v/checker/struct.v

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -851,7 +851,10 @@ or use an explicit `unsafe{ a[..] }`, if you do not want a copy of the slice.',
851851
if mut init_field.expr is ast.CallExpr
852852
&& init_field.expr.return_type.has_flag(.generic) {
853853
expected_type := c.unwrap_generic(init_field.expected_type)
854-
got_type_ret := c.unwrap_generic(init_field.expr.return_type)
854+
mut got_type_ret := c.unwrap_generic(init_field.expr.return_type)
855+
if init_field.expr.or_block.kind != .absent {
856+
got_type_ret = got_type_ret.clear_option_and_result()
857+
}
855858
if expected_type != got_type_ret {
856859
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)}`',
857860
init_field.expr.pos)
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
struct Test[T] {
2+
pub:
3+
value T
4+
}
5+
6+
struct AuxTest[T] {
7+
pub:
8+
any_value Test[T]
9+
}
10+
11+
fn decode[T](arg Test[T]) !Test[T] {
12+
return Test[T]{}
13+
}
14+
15+
pub fn initializing[T]() !AuxTest[T] {
16+
return AuxTest[T]{
17+
any_value: decode[T](Test[T]{})!
18+
}
19+
}
20+
21+
fn test_main() {
22+
dump(initializing[int]()!)
23+
}

0 commit comments

Comments
 (0)