1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

cgen: fix embed field access from reference (#7724)

This commit is contained in:
Daniel Däschle 2020-12-30 21:50:58 +01:00 committed by GitHub
parent c3e8e2ad31
commit b4c5fa8ca0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 3 deletions

View File

@ -2824,10 +2824,15 @@ fn (mut g Gen) selector_expr(node ast.SelectorExpr) {
if node.from_embed_type != 0 {
embed_sym := g.table.get_type_symbol(node.from_embed_type)
embed_name := embed_sym.embed_name()
g.write('.$embed_name')
if node.expr_type.is_ptr() {
g.write('->')
} else {
g.write('.')
}
g.write(embed_name)
}
}
if node.expr_type.is_ptr() || sym.kind == .chan {
if (node.expr_type.is_ptr() || sym.kind == .chan) && node.from_embed_type == 0 {
g.write('->')
} else {
// g.write('. /*typ= $it.expr_type */') // ${g.typ(it.expr_type)} /')

View File

@ -86,7 +86,9 @@ fn test_embed_is_public() {
assert a.Context.name == ''
}
struct Eggs {}
struct Eggs {
name string
}
fn (f &Eggs) test(x int) int {
return x
@ -96,11 +98,20 @@ struct Breakfast {
Eggs
}
fn (b &Breakfast) name() string {
return b.name
}
fn test_embed_method_receiver_ptr() {
b := Breakfast{}
assert b.test(5) == 5
}
fn test_embed_field_receiver_ptr() {
b := Breakfast{}
assert b.name() == ''
}
fn test_embed_mutable() {
mut a := field_publicity.App{}
a.Context = field_publicity.Context{}