Skip to content

Commit

Permalink
fix visit_entities macro
Browse files Browse the repository at this point in the history
  • Loading branch information
Tim Overbeek committed Feb 19, 2025
1 parent 2fe51a0 commit 9ada21b
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions crates/bevy_ecs/macros/src/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,15 @@ fn visit_entities(data: &Data, bevy_ecs_path: &Path, is_relationship: bool) -> T
Data::Struct(DataStruct { ref fields, .. }) => {
let mut visited_fields = Vec::new();
let mut visited_indices = Vec::new();

if is_relationship {
if let Some(field) = relationship_field(fields, fields.span()).ok().flatten() {
match field.ident {
Some(ref ident) => visited_fields.push(ident.clone()),
None => visited_indices.push(Index::from(0)),
}
}
}
match fields {
Fields::Named(fields) => {
for field in &fields.named {
Expand All @@ -276,9 +285,7 @@ fn visit_entities(data: &Data, bevy_ecs_path: &Path, is_relationship: bool) -> T
}
Fields::Unnamed(fields) => {
for (index, field) in fields.unnamed.iter().enumerate() {
if index == 0 && is_relationship {
visited_indices.push(Index::from(0));
} else if field
if field
.attrs
.iter()
.any(|a| a.meta.path().is_ident(ENTITIES_ATTR))
Expand All @@ -289,7 +296,6 @@ fn visit_entities(data: &Data, bevy_ecs_path: &Path, is_relationship: bool) -> T
}
Fields::Unit => {}
}

if visited_fields.is_empty() && visited_indices.is_empty() {
TokenStream2::new()
} else {
Expand Down

0 comments on commit 9ada21b

Please sign in to comment.