Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Merged by Bors] - bevy_reflect: Fix apply method for Option<T> #5780

Closed
wants to merge 4 commits into from

Conversation

MrGVSV
Copy link
Member

@MrGVSV MrGVSV commented Aug 24, 2022

Objective

#5658 made it so that FromReflect was used as the bound for T in Option<T>. However, it did not use this change effectively for the implementation of Reflect::apply (it was still using take, which would fail for Dynamic types).

Additionally, the changes were not consistent with other methods within the file, such as the ones for Vec<T> and HashMap<K, V>.

Solution

Update Option<T> to fallback on FromReflect if take fails, instead of wholly relying on one or the other.

I also chose to update the error messages, as they weren't all too descriptive before.


Changelog

  • Use FromReflect::from_reflect as a fallback in the Reflect::apply implementation for Option<T>

@alice-i-cecile alice-i-cecile added C-Bug An unexpected or incorrect behavior A-Reflection Runtime information about types labels Aug 24, 2022
@MrGVSV MrGVSV removed the C-Bug An unexpected or incorrect behavior label Aug 24, 2022
@MrGVSV MrGVSV added the C-Bug An unexpected or incorrect behavior label Aug 24, 2022
@MrGVSV
Copy link
Member Author

MrGVSV commented Aug 24, 2022

I just added a test which subsequently alerted me of another bug which has been fixed as well.

@alice-i-cecile alice-i-cecile added the S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it label Aug 24, 2022
})
.clone_value()
.take::<T>()
.unwrap_or_else(|value| {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems reasonable for the current impl. Stuff like this makes me want to revisit mixing "dynamic type" reflection and "actual type" reflection. But thats a conversation for another day :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds like a good time to revisit bevyengine/rfcs#56 😉

@cart
Copy link
Member

cart commented Aug 24, 2022

bors r+

bors bot pushed a commit that referenced this pull request Aug 24, 2022
# Objective

#5658 made it so that `FromReflect` was used as the bound for `T` in `Option<T>`. However, it did not use this change effectively for the implementation of `Reflect::apply` (it was still using `take`, which would fail for Dynamic types).

Additionally, the changes were not consistent with other methods within the file, such as the ones for `Vec<T>` and `HashMap<K, V>`.

## Solution

Update `Option<T>` to fallback on `FromReflect` if `take` fails, instead of wholly relying on one or the other.

I also chose to update the error messages, as they weren't all too descriptive before.

---

## Changelog

- Use `FromReflect::from_reflect` as a fallback in the `Reflect::apply` implementation for `Option<T>`
@bors bors bot changed the title bevy_reflect: Fix apply method for Option<T> [Merged by Bors] - bevy_reflect: Fix apply method for Option<T> Aug 24, 2022
@bors bors bot closed this Aug 24, 2022
@MrGVSV MrGVSV deleted the reflect-option-bounds-2 branch August 24, 2022 21:05
maccesch pushed a commit to Synphonyte/bevy that referenced this pull request Sep 28, 2022
# Objective

bevyengine#5658 made it so that `FromReflect` was used as the bound for `T` in `Option<T>`. However, it did not use this change effectively for the implementation of `Reflect::apply` (it was still using `take`, which would fail for Dynamic types).

Additionally, the changes were not consistent with other methods within the file, such as the ones for `Vec<T>` and `HashMap<K, V>`.

## Solution

Update `Option<T>` to fallback on `FromReflect` if `take` fails, instead of wholly relying on one or the other.

I also chose to update the error messages, as they weren't all too descriptive before.

---

## Changelog

- Use `FromReflect::from_reflect` as a fallback in the `Reflect::apply` implementation for `Option<T>`
james7132 pushed a commit to james7132/bevy that referenced this pull request Oct 28, 2022
# Objective

bevyengine#5658 made it so that `FromReflect` was used as the bound for `T` in `Option<T>`. However, it did not use this change effectively for the implementation of `Reflect::apply` (it was still using `take`, which would fail for Dynamic types).

Additionally, the changes were not consistent with other methods within the file, such as the ones for `Vec<T>` and `HashMap<K, V>`.

## Solution

Update `Option<T>` to fallback on `FromReflect` if `take` fails, instead of wholly relying on one or the other.

I also chose to update the error messages, as they weren't all too descriptive before.

---

## Changelog

- Use `FromReflect::from_reflect` as a fallback in the `Reflect::apply` implementation for `Option<T>`
ItsDoot pushed a commit to ItsDoot/bevy that referenced this pull request Feb 1, 2023
# Objective

bevyengine#5658 made it so that `FromReflect` was used as the bound for `T` in `Option<T>`. However, it did not use this change effectively for the implementation of `Reflect::apply` (it was still using `take`, which would fail for Dynamic types).

Additionally, the changes were not consistent with other methods within the file, such as the ones for `Vec<T>` and `HashMap<K, V>`.

## Solution

Update `Option<T>` to fallback on `FromReflect` if `take` fails, instead of wholly relying on one or the other.

I also chose to update the error messages, as they weren't all too descriptive before.

---

## Changelog

- Use `FromReflect::from_reflect` as a fallback in the `Reflect::apply` implementation for `Option<T>`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Reflection Runtime information about types C-Bug An unexpected or incorrect behavior S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants