@@ -35,7 +35,7 @@ impl_reflect_value!(HashSet<T: Serialize + Hash + Eq + Clone + for<'de> Deserial
3535impl_reflect_value ! ( Range <T : Serialize + Clone + for <' de> Deserialize <' de> + Send + Sync + ' static >( Serialize , Deserialize ) ) ;
3636impl_reflect_value ! ( Duration ) ;
3737
38- impl < T : Reflect > List for Vec < T > {
38+ impl < T : Reflect + Default > List for Vec < T > {
3939 fn get ( & self , index : usize ) -> Option < & dyn Reflect > {
4040 <[ T ] >:: get ( self , index) . map ( |value| value as & dyn Reflect )
4141 }
@@ -57,17 +57,17 @@ impl<T: Reflect> List for Vec<T> {
5757
5858 fn push ( & mut self , value : Box < dyn Reflect > ) {
5959 let value = value. take :: < T > ( ) . unwrap_or_else ( |value| {
60- panic ! (
61- "Attempted to push invalid value of type {}." ,
62- value. type_name ( )
63- )
60+ // If `value` is not of the same type, it may be a dynamic type that needs to be applied
61+ let mut new_value = T :: default ( ) ;
62+ ( & mut new_value as & mut dyn Reflect ) . apply ( value. as_ref ( ) ) ;
63+ new_value
6464 } ) ;
6565 Vec :: push ( self , value) ;
6666 }
6767}
6868
6969// SAFE: any and any_mut both return self
70- unsafe impl < T : Reflect > Reflect for Vec < T > {
70+ unsafe impl < T : Reflect + Default > Reflect for Vec < T > {
7171 fn type_name ( & self ) -> & str {
7272 std:: any:: type_name :: < Self > ( )
7373 }
@@ -114,7 +114,7 @@ unsafe impl<T: Reflect> Reflect for Vec<T> {
114114 }
115115}
116116
117- impl < T : Reflect + for < ' de > Deserialize < ' de > > GetTypeRegistration for Vec < T > {
117+ impl < T : Reflect + Default + for < ' de > Deserialize < ' de > > GetTypeRegistration for Vec < T > {
118118 fn get_type_registration ( ) -> TypeRegistration {
119119 let mut registration = TypeRegistration :: of :: < Vec < T > > ( ) ;
120120 registration. insert :: < ReflectDeserialize > ( FromType :: < Vec < T > > :: from_type ( ) ) ;
0 commit comments