You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Created a reflected E::B with only one field by deserializing it from JSON using TypedReflectDeserializer.
Applied the incomplete reflected E::B to the enum with value E::A, using Reflect::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.
The text was updated successfully, but these errors were encountered:
UkoeHB
changed the title
Reflect::apply panics when applying incomplete enum value
ReflectDeserializer does not error when deserializing incomplete enum value
Mar 7, 2024
@mrchantey not sure if they are related, will need to test out the fix from #12464 to see. My problem doesn't seem to be deserialization, it's applying reflected enums to existing structs.
Bevy version
v0.13.0
What you did
E::A
.E::B
with only one field by deserializing it from JSON usingTypedReflectDeserializer
.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 ofReflect::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.The text was updated successfully, but these errors were encountered: