Fix Box<dyn Reflect> struct with a hashmap in it panicking when clone_value is called on it (#8184)

# Objective

- Fix the issue described in #8183: Box<dyn Reflect> structs with a
hashmap in them will panic when clone_value is called on it
- Fixes: #8183

## Solution

- Updates the implementation of Reflect for Hashmaps to make clone_value
call from_reflect on the key before inserting it into the new struct
This commit is contained in:
Noah 2023-04-21 22:55:53 -04:00 committed by GitHub
parent 37ad73d8fc
commit a9f766ceb2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -399,7 +399,10 @@ macro_rules! impl_reflect_for_hashmap {
let mut dynamic_map = DynamicMap::default();
dynamic_map.set_name(self.type_name().to_string());
for (k, v) in self {
dynamic_map.insert_boxed(k.clone_value(), v.clone_value());
let key = K::from_reflect(k).unwrap_or_else(|| {
panic!("Attempted to clone invalid key of type {}.", k.type_name())
});
dynamic_map.insert_boxed(Box::new(key), v.clone_value());
}
dynamic_map
}