1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

cgen: fix struct init with update expr (fix #15595) (#15603)

This commit is contained in:
yuyi 2022-08-30 14:22:14 +08:00 committed by GitHub
parent e355ae7b3c
commit 0876cf86ed
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 0 deletions

View File

@ -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('->')

View File

@ -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
}