bevy/examples/reflection
Gino Valente 6e95f297ea
bevy_reflect: Automatic arg count validation (#15145)
# Objective

Functions created into `DynamicFunction[Mut]` do not currently validate
the number of arguments they are given before calling the function.

I originally did this because I felt users would want to validate this
themselves in the function rather than have it be done
behind-the-scenes. I'm now realizing, however, that we could remove this
boilerplate and if users wanted to check again then they would still be
free to do so (it'd be more of a sanity check at that point).

## Solution

Automatically validate the number of arguments passed to
`DynamicFunction::call` and `DynamicFunctionMut::call[_once]`.

This is a pretty trivial change since we just need to compare the length
of the `ArgList` to the length of the `[ArgInfo]` in the function's
`FunctionInfo`.

I also ran the benchmarks just in case and saw no regression by doing
this.

## Testing

You can test locally by running:

```
cargo test --package bevy_reflect --all-features
```
2024-09-23 17:03:14 +00:00
..
custom_attributes.rs bevy_reflect: Custom attributes (#11659) 2024-05-20 19:30:21 +00:00
dynamic_types.rs bevy_reflect: Add ReflectRef/ReflectMut/ReflectOwned convenience casting methods (#15235) 2024-09-23 16:50:46 +00:00
function_reflection.rs bevy_reflect: Automatic arg count validation (#15145) 2024-09-23 17:03:14 +00:00
generic_reflection.rs bevy_reflect: Recursive registration (#5781) 2024-03-04 19:04:10 +00:00
reflection.rs reflect: implement the unique reflect rfc (#7207) 2024-08-12 17:01:41 +00:00
reflection_types.rs bevy_reflect: Add Function trait (#15205) 2024-09-22 14:19:12 +00:00
type_data.rs bevy_reflect: Add DynamicTyped trait (#15108) 2024-09-13 17:17:10 +00:00