cgen: fix error, when a struct with over 8 fields, is used as a method receiver directly.
parent
022fae1e7f
commit
eea46c4e1a
|
@ -22,6 +22,10 @@ fn (mut g Gen) struct_init(node ast.StructInit) {
|
||||||
if is_amp {
|
if is_amp {
|
||||||
g.out.go_back(1) // delete the `&` already generated in `prefix_expr()
|
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 {
|
if g.is_shared && !g.inside_opt_data && !g.is_arraymap_set {
|
||||||
mut shared_typ := node.typ.set_flag(.shared_f)
|
mut shared_typ := node.typ.set_flag(.shared_f)
|
||||||
shared_styp = g.typ(shared_typ)
|
shared_styp = g.typ(shared_typ)
|
||||||
|
|
|
@ -28,3 +28,30 @@ fn test_op() {
|
||||||
dump(a)
|
dump(a)
|
||||||
dump(b)
|
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
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue