checker: fix struct field init with generic fn variable (fix #20847) (#20878)

This commit is contained in:
yuyi 2024-02-20 23:34:55 +08:00 committed by GitHub
parent 0b792c541a
commit 13fbf35f66
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 26 additions and 1 deletions

View File

@ -189,8 +189,8 @@ fn (mut c Checker) assign_stmt(mut node ast.AssignStmt) {
if is_decl || is_shared_re_assign {
// check generic struct init and return unwrap generic struct type
if mut right is ast.StructInit {
c.expr(mut right)
if right.typ.has_flag(.generic) {
c.expr(mut right)
right_type = right.typ
}
} else if mut right is ast.PrefixExpr {

View File

@ -0,0 +1,25 @@
struct ClassInfo {
func fn () = unsafe { nil }
}
pub fn func2[T]() {
}
pub fn func1[T]() {
ci := ClassInfo{
func: func2[T]
}
ci.func()
}
struct Struct1 {}
struct Struct2 {}
fn test_struct_field_init_with_generic_fn() {
func1[i32]()
func1[bool]()
func1[Struct1]()
func1[Struct2]()
assert true
}