Skip to content

Commit

Permalink
fix embed check
Browse files Browse the repository at this point in the history
  • Loading branch information
Delta456 committed Sep 11, 2024
1 parent 62e0a3a commit 96ea361
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions vlib/v/checker/struct.v
Original file line number Diff line number Diff line change
Expand Up @@ -979,9 +979,20 @@ fn (mut c Checker) check_uninitialized_struct_fields_and_embeds(node ast.StructI
for embed in info.embeds {
embed_sym := c.table.sym(embed)
if embed_sym.info is ast.Struct {
if embed_sym.info.is_union && node.init_fields.len > 1 {
c.error('embed union `${embed_sym.name}` can have only one field initialised',
node.pos)
if embed_sym.info.is_union {
mut embed_union_fields := c.table.struct_fields(embed_sym)
mut found := false
for init_field in inited_fields {
for union_field in embed_union_fields {
if init_field == union_field.name && found {
c.error('embed union `${embed_sym.name}` can have only one field initialised',
node.pos)
}
if init_field == union_field.name {
found = true
}
}
}
}
}
mut zero_struct_init := ast.StructInit{
Expand Down

0 comments on commit 96ea361

Please sign in to comment.