Skip to content

Commit 083eb34

Browse files
authored
checker: fix struct init update with generics (fix #20136) (#20139)
1 parent cfcbcb4 commit 083eb34

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

vlib/v/checker/struct.v

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -874,9 +874,10 @@ or use an explicit `unsafe{ a[..] }`, if you do not want a copy of the slice.',
874874
if node.has_update_expr {
875875
update_type := c.expr(mut node.update_expr)
876876
node.update_expr_type = update_type
877+
expr_sym := c.table.final_sym(c.unwrap_generic(update_type))
877878
if node.update_expr is ast.ComptimeSelector {
878879
c.error('cannot use struct update syntax in compile time expressions', node.update_expr_pos)
879-
} else if c.table.final_sym(update_type).kind != .struct_ {
880+
} else if expr_sym.kind != .struct_ {
880881
s := c.table.type_to_str(update_type)
881882
c.error('expected struct, found `${s}`', node.update_expr.pos())
882883
} else if update_type != node.typ {
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
struct Foo {
2+
a int
3+
b string
4+
isbool bool
5+
}
6+
7+
fn do[T](f T) T {
8+
return T{
9+
...f
10+
isbool: true
11+
}
12+
}
13+
14+
fn test_main() {
15+
foo := do(Foo{
16+
a: 1
17+
b: '2'
18+
})
19+
assert foo.a == 1 && foo.b == '2' && foo.isbool
20+
}

0 commit comments

Comments
 (0)