checker: fix checking return type call disregarding unwrapping (fix #25140) (#25143)

This commit is contained in:
Felipe Pena 2025-08-20 16:39:38 -03:00 committed by GitHub
parent 98ca0f075e
commit aa7de61e44
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 27 additions and 1 deletions

View file

@ -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
&& init_field.expr.return_type.has_flag(.generic) {
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 {
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)

View 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]()!)
}