diff --git a/vlib/v/gen/cgen.v b/vlib/v/gen/cgen.v index ffa5fd1768..892fd531c2 100644 --- a/vlib/v/gen/cgen.v +++ b/vlib/v/gen/cgen.v @@ -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)} /') diff --git a/vlib/v/tests/struct_embed_test.v b/vlib/v/tests/struct_embed_test.v index cf18f2b02b..ac0165165f 100644 --- a/vlib/v/tests/struct_embed_test.v +++ b/vlib/v/tests/struct_embed_test.v @@ -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{}