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

Deriving Bundle fails for nested bundles with generic parameters #1873

Closed
concave-sphere opened this issue Apr 10, 2021 · 1 comment
Closed
Assignees
Labels
A-ECS Entities, components, systems, and events C-Bug An unexpected or incorrect behavior

Comments

@concave-sphere
Copy link

concave-sphere commented Apr 10, 2021

Bevy version

0.5

Operating system & version

Debian GNU/Linux "buster"

What you did

Tried to derive Bundle for a struct containing a type with generic parameters:

#[derive(Bundle)]
struct Bar<T: bevy::ecs::component::Component> {
    f: T,
}

#[derive(Bundle)]
struct Foo {
    #[bundle]
    bar: Bar<String>,
}

What you expected to happen

I should get a Bundle implementation for Foo that includes Bar as a sub-bundle.

What actually happened

The code produced by the macro fails to compile:

error: comparison operators cannot be chained
  --> src/main.rs:13:13
   |
13 |     bar: Bar<String>,
   |             ^      ^
   |
help: use `::<...>` instead of `<...>` to specify type or const arguments
   |
13 |     bar: Bar::<String>,
   |             ^^

error: proc-macro derive produced unparseable tokens
  --> src/main.rs:10:10
   |
10 | #[derive(Bundle)]
   |          ^^^^^^

error: aborting due to 2 previous errors

Additional information

Using a type alias is a workaround:

#[derive(Bundle)]
struct Bar<T: bevy::ecs::component::Component> {
    f: T,
}

type BarString = Bar<String>;

#[derive(Bundle)]
struct Foo {
    #[bundle]
    bar: BarString,
}

(edited to remove an unrelated bug from my example code and add the workaround)

@alice-i-cecile alice-i-cecile added C-Bug An unexpected or incorrect behavior A-ECS Entities, components, systems, and events labels Apr 10, 2021
@YohDeadfall
Copy link
Member

While another issue awaits some clarification on change from Carter, I can take this one.

@bors bors bot closed this as completed in 2231492 Apr 15, 2021
ostwilkens pushed a commit to ostwilkens/bevy that referenced this issue Jul 27, 2021
Fixes bevyengine#1873. Types should be enclosed in angular brackets to avoid ambiquity and to correctly resolve associated functions.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-ECS Entities, components, systems, and events C-Bug An unexpected or incorrect behavior
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants