mirror of
https://github.com/vlang/v.git
synced 2025-09-10 07:47:20 -04:00
parent
cfcbcb416a
commit
083eb3450b
@ -874,9 +874,10 @@ or use an explicit `unsafe{ a[..] }`, if you do not want a copy of the slice.',
|
||||
if node.has_update_expr {
|
||||
update_type := c.expr(mut node.update_expr)
|
||||
node.update_expr_type = update_type
|
||||
expr_sym := c.table.final_sym(c.unwrap_generic(update_type))
|
||||
if node.update_expr is ast.ComptimeSelector {
|
||||
c.error('cannot use struct update syntax in compile time expressions', node.update_expr_pos)
|
||||
} else if c.table.final_sym(update_type).kind != .struct_ {
|
||||
} else if expr_sym.kind != .struct_ {
|
||||
s := c.table.type_to_str(update_type)
|
||||
c.error('expected struct, found `${s}`', node.update_expr.pos())
|
||||
} else if update_type != node.typ {
|
||||
|
20
vlib/v/tests/struct_init_update_with_generics_test.v
Normal file
20
vlib/v/tests/struct_init_update_with_generics_test.v
Normal file
@ -0,0 +1,20 @@
|
||||
struct Foo {
|
||||
a int
|
||||
b string
|
||||
isbool bool
|
||||
}
|
||||
|
||||
fn do[T](f T) T {
|
||||
return T{
|
||||
...f
|
||||
isbool: true
|
||||
}
|
||||
}
|
||||
|
||||
fn test_main() {
|
||||
foo := do(Foo{
|
||||
a: 1
|
||||
b: '2'
|
||||
})
|
||||
assert foo.a == 1 && foo.b == '2' && foo.isbool
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user