Skip to content

Commit 13fbf35

Browse files
authored
checker: fix struct field init with generic fn variable (fix #20847) (#20878)
1 parent 0b792c5 commit 13fbf35

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

vlib/v/checker/assign.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,8 @@ fn (mut c Checker) assign_stmt(mut node ast.AssignStmt) {
189189
if is_decl || is_shared_re_assign {
190190
// check generic struct init and return unwrap generic struct type
191191
if mut right is ast.StructInit {
192+
c.expr(mut right)
192193
if right.typ.has_flag(.generic) {
193-
c.expr(mut right)
194194
right_type = right.typ
195195
}
196196
} else if mut right is ast.PrefixExpr {
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
struct ClassInfo {
2+
func fn () = unsafe { nil }
3+
}
4+
5+
pub fn func2[T]() {
6+
}
7+
8+
pub fn func1[T]() {
9+
ci := ClassInfo{
10+
func: func2[T]
11+
}
12+
ci.func()
13+
}
14+
15+
struct Struct1 {}
16+
17+
struct Struct2 {}
18+
19+
fn test_struct_field_init_with_generic_fn() {
20+
func1[i32]()
21+
func1[bool]()
22+
func1[Struct1]()
23+
func1[Struct2]()
24+
assert true
25+
}

0 commit comments

Comments
 (0)