Open
Description
Bevy version
v0.13.0
What you did
#[derive(Reflect)]
enum E {
A,
B{ a: usize, b: usize },
}
- Initialized an enum to
E::A
. - Created a reflected
E::B
with only one field by deserializing it from JSON usingTypedReflectDeserializer
. - Applied the incomplete reflected
E::B
to the enum with valueE::A
, usingReflect::apply
.
What went wrong
This panic triggered. Basically, the reflect machinery cannot apply an incomplete enum variant to a different enum variant.
This is a bug because I expect the deserialize-from-JSON step to catch this kind of error so you never hit the panic. Note that, in contrast to enums, if you reflect-deserialize a struct with missing fields, then a serialization error will occur.
Additional information
You can avoid this panic by using FromReflect::from_reflect
instead of Reflect::apply
, which will fail without panicking.
If you don't want FromReflect::from_reflect
to fail when a field is missing, use #[reflect(default)]
on potentially-missing fields.