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

cgen: fix error, when a struct with over 8 fields, is used as a method receiver directly.

This commit is contained in:
Delyan Angelov 2022-04-07 17:20:14 +03:00
parent 022fae1e7f
commit eea46c4e1a
No known key found for this signature in database
GPG Key ID: 66886C0F12D595ED
2 changed files with 31 additions and 0 deletions

View File

@ -22,6 +22,10 @@ fn (mut g Gen) struct_init(node ast.StructInit) {
if is_amp {
g.out.go_back(1) // delete the `&` already generated in `prefix_expr()
}
g.write('(')
defer {
g.write(')')
}
if g.is_shared && !g.inside_opt_data && !g.is_arraymap_set {
mut shared_typ := node.typ.set_flag(.shared_f)
shared_styp = g.typ(shared_typ)

View File

@ -28,3 +28,30 @@ fn test_op() {
dump(a)
dump(b)
}
struct ManyFields {
mut:
f01 int
f02 int
f03 int
f04 int
f05 int
f06 int
f07 int
f08 int
f09 int
f10 int
f11 int
f12 int
}
fn (mf ManyFields) inc() ManyFields {
mut res := mf
res.f01 += 1
return res
}
fn test_a_struct_with_many_fields_can_be_used_as_receiver_directly_without_assigning_to_an_intermediate_variable() {
x := ManyFields{}.inc()
assert x.f01 == 1
}