Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cgen: fix codegen for alias struct embed #23353

Merged
merged 1 commit into from
Jan 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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{})
}'
}
Loading