Skip to content

Commit

Permalink
cgen: fix reference embed method call (#15842)
Browse files Browse the repository at this point in the history
  • Loading branch information
yuyi98 committed Sep 22, 2022
1 parent 78f8b9e commit 44c3fce
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
10 changes: 10 additions & 0 deletions vlib/v/gen/c/fn.v
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
23 changes: 23 additions & 0 deletions vlib/v/tests/embed_method_call_test.v
Original file line number Diff line number Diff line change
@@ -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]
}

0 comments on commit 44c3fce

Please sign in to comment.