mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
parent
e355ae7b3c
commit
0876cf86ed
@ -195,7 +195,9 @@ fn (mut g Gen) struct_init(node ast.StructInit) {
|
||||
if is_update_tmp_var {
|
||||
g.write(tmp_update_var)
|
||||
} else {
|
||||
g.write('(')
|
||||
g.expr(node.update_expr)
|
||||
g.write(')')
|
||||
}
|
||||
if node.update_expr_type.is_ptr() {
|
||||
g.write('->')
|
||||
|
@ -30,3 +30,21 @@ fn test_struct_init_with_update_expr() {
|
||||
assert o.height == 175
|
||||
assert o.age == 21
|
||||
}
|
||||
|
||||
struct Foo {
|
||||
s string
|
||||
n int
|
||||
}
|
||||
|
||||
fn test_struct_init_with_update_expr2() {
|
||||
f := &Foo{
|
||||
s: 'AA'
|
||||
}
|
||||
b := Foo{
|
||||
...*f
|
||||
n: 3
|
||||
}
|
||||
println(b)
|
||||
assert b.s == 'AA'
|
||||
assert b.n == 3
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user