Skip to content

Commit

Permalink
cgen: fix codegen for alias struct embed (fix #23347) (#23353)
Browse files Browse the repository at this point in the history
  • Loading branch information
felipensp authored Jan 3, 2025
1 parent c50d4ee commit 1bfeda6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
6 changes: 5 additions & 1 deletion vlib/v/gen/c/struct.v
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,11 @@ fn (mut g Gen) struct_init(node ast.StructInit) {
embed_sym := g.table.sym(embed)
embed_name := embed_sym.embed_name()
if embed_name !in inited_fields {
embed_info := embed_sym.info as ast.Struct
embed_info := if embed_sym.info is ast.Struct {
embed_sym.info
} else {
g.table.final_sym(embed).info as ast.Struct
}
embed_field_names := embed_info.fields.map(it.name)
fields_to_embed := init_fields_to_embed.filter(it.name !in used_embed_fields
&& it.name in embed_field_names)
Expand Down
13 changes: 13 additions & 0 deletions vlib/v/tests/struct_with_alias_embed_test.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
struct Foo1 {}

type Foo2 = Foo1

struct Bar {
Foo2
}

fn test_main() {
assert Bar{}.str() == 'Bar{
Foo2: Foo2(Foo1{})
}'
}

0 comments on commit 1bfeda6

Please sign in to comment.