Skip to content

#[derive(Reflect)] on enum that wraps another enum does not work #6783

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

Closed
jenanwise opened this issue Nov 28, 2022 · 6 comments
Closed

#[derive(Reflect)] on enum that wraps another enum does not work #6783

jenanwise opened this issue Nov 28, 2022 · 6 comments
Labels
A-Reflection Runtime information about types C-Docs An addition or correction to our documentation

Comments

@jenanwise
Copy link

Bevy version

Tried: 0.9 and 523072902cecad440b5d2109077e437fcb7580b6

What you did

Deriving Reflect on a simple enum works:

#[derive(Reflect)]
enum Inner {
    Foo,
}

But deriving Reflect on an enum that wraps another enum does not:

#[derive(Reflect)] // <-- the trait `FromReflect` is not implemented for `Inner`
enum Outer {
    Inner(Inner),
}
@jenanwise jenanwise added C-Bug An unexpected or incorrect behavior S-Needs-Triage This issue needs to be labelled labels Nov 28, 2022
@jakobhellermann
Copy link
Contributor

You need to derive FromReflect for the inner enum as well. I forgot why it is required, but without it the enum can't be reflected.

@alice-i-cecile alice-i-cecile added C-Docs An addition or correction to our documentation A-Reflection Runtime information about types and removed C-Bug An unexpected or incorrect behavior S-Needs-Triage This issue needs to be labelled labels Nov 28, 2022
@alice-i-cecile
Copy link
Member

This should be documented on the Reflect trait via a doc test :)

@MrGVSV
Copy link
Member

MrGVSV commented Dec 2, 2022

You need to derive FromReflect for the inner enum as well. I forgot why it is required, but without it the enum can't be reflected.

It's required because of Reflect::apply. Just like with Vec<T: FromReflect> we need to ensure we can create concrete instances of new data. For Vec<T> this means possibly inserting a brand new value. For enums, this means possibly setting it to a different variant.

@MrGVSV MrGVSV added this to Reflection Dec 2, 2022
@MrGVSV MrGVSV moved this to Open in Reflection Dec 2, 2022
@MrGVSV
Copy link
Member

MrGVSV commented Dec 19, 2022

Should we close this out and open a new issue for the documentation on Reflect (or maybe Enum) to indicate this?

@alice-i-cecile
Copy link
Member

Yes please. Ping me when you've made one and I'll do so.

@MrGVSV
Copy link
Member

MrGVSV commented Dec 19, 2022

@alice-i-cecile created #6985

Repository owner moved this from Open to Done in Reflection Dec 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Reflection Runtime information about types C-Docs An addition or correction to our documentation
Projects
Status: Done
Development

No branches or pull requests

4 participants