1
0
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:
yuyi 2022-09-22 18:53:11 +08:00 committed by GitHub
parent 78f8b9eb28
commit 44c3fcecd9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 33 additions and 0 deletions

View File

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

View 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]
}