cgen: fix fn mut val of interface type (#10568)
parent
878efcdade
commit
51075ffa15
|
@ -487,6 +487,9 @@ fn (mut g Gen) infix_expr_left_shift_op(node ast.InfixExpr) {
|
|||
if needs_clone {
|
||||
g.write('string_clone(')
|
||||
}
|
||||
if right.unaliased_sym.kind == .interface_ && node.right.is_auto_deref_var() {
|
||||
g.write('*')
|
||||
}
|
||||
g.expr_with_cast(node.right, node.right_type, array_info.elem_type)
|
||||
if needs_clone {
|
||||
g.write(')')
|
||||
|
|
|
@ -43,3 +43,27 @@ fn test_fn_mut_args_of_array_last() {
|
|||
m.ar << 99
|
||||
assert pass_array_mut(mut m.ar) == 99
|
||||
}
|
||||
|
||||
interface ChildInterface {
|
||||
data int
|
||||
}
|
||||
|
||||
struct Child {
|
||||
data int
|
||||
}
|
||||
|
||||
struct Parent {
|
||||
mut:
|
||||
children []ChildInterface
|
||||
}
|
||||
|
||||
fn (mut p Parent) add(mut x ChildInterface) {
|
||||
p.children << x
|
||||
}
|
||||
|
||||
fn test_fn_mut_args_of_interface() {
|
||||
mut x := Parent{}
|
||||
x.add(mut Child{ data: 123 })
|
||||
println(x.children[0].data)
|
||||
assert x.children[0].data == 123
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue