mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
cgen: fix reference embed method call (#15842)
This commit is contained in:
parent
78f8b9eb28
commit
44c3fcecd9
@ -1086,6 +1086,16 @@ fn (mut g Gen) method_call(node ast.CallExpr) {
|
||||
g.write('(map[]){')
|
||||
g.expr(node.left)
|
||||
g.write('}[0]')
|
||||
} else if node.from_embed_types.len > 0 {
|
||||
n_ptr := node.left_type.nr_muls() - 1
|
||||
if n_ptr > 0 {
|
||||
g.write('(')
|
||||
g.write('*'.repeat(n_ptr))
|
||||
g.expr(node.left)
|
||||
g.write(')')
|
||||
} else {
|
||||
g.expr(node.left)
|
||||
}
|
||||
} else {
|
||||
g.expr(node.left)
|
||||
}
|
||||
|
23
vlib/v/tests/embed_method_call_test.v
Normal file
23
vlib/v/tests/embed_method_call_test.v
Normal file
@ -0,0 +1,23 @@
|
||||
struct Access {}
|
||||
|
||||
fn (access &Access) acc() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
struct Field {
|
||||
Access
|
||||
}
|
||||
|
||||
fn test_embed_method_call() {
|
||||
mut fields := []&Field{}
|
||||
fields << &Field{}
|
||||
|
||||
mut rets := []bool{}
|
||||
for mut field in fields {
|
||||
println(field.acc())
|
||||
rets << field.acc()
|
||||
}
|
||||
|
||||
assert rets.len == 1
|
||||
assert rets[0]
|
||||
}
|
Loading…
Reference in New Issue
Block a user