From a44278aee6e7b8e92c32952ded0285effa01d06f Mon Sep 17 00:00:00 2001 From: eckz <567737+eckz@users.noreply.github.com> Date: Thu, 15 Aug 2024 16:10:52 +0200 Subject: [PATCH] Making `DynamicEnum::is_dynamic()` return true (#14732) # Objective - Right now `DynamicEnum::is_dynamic()` is returning `false`. I don't think this was expected, since the rest of `Dynamic*` types return `true`. ## Solution - Making `DynamicEnum::is_dynamic()` return true ## Testing - Added an extra unit test to verify that `.is_dynamic()` returns `true`. --- crates/bevy_reflect/src/enums/dynamic_enum.rs | 5 +++++ crates/bevy_reflect/src/enums/mod.rs | 6 ++++++ 2 files changed, 11 insertions(+) diff --git a/crates/bevy_reflect/src/enums/dynamic_enum.rs b/crates/bevy_reflect/src/enums/dynamic_enum.rs index c4aa8555cb..bf1c1fa6dd 100644 --- a/crates/bevy_reflect/src/enums/dynamic_enum.rs +++ b/crates/bevy_reflect/src/enums/dynamic_enum.rs @@ -415,6 +415,11 @@ impl PartialReflect for DynamicEnum { enum_debug(self, f)?; write!(f, ")") } + + #[inline] + fn is_dynamic(&self) -> bool { + true + } } impl_type_path!((in bevy_reflect) DynamicEnum); diff --git a/crates/bevy_reflect/src/enums/mod.rs b/crates/bevy_reflect/src/enums/mod.rs index 043aaad49b..95a94e68e9 100644 --- a/crates/bevy_reflect/src/enums/mod.rs +++ b/crates/bevy_reflect/src/enums/mod.rs @@ -211,6 +211,12 @@ mod tests { assert_eq!(MyEnum::A, value); } + #[test] + fn dynamic_enum_should_return_is_dynamic() { + let dyn_enum = DynamicEnum::from(MyEnum::B(123, 321)); + assert!(dyn_enum.is_dynamic()); + } + #[test] fn enum_should_iterate_fields() { // === Unit === //