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

Fix #633: Check if this extends wrapper #634

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

n3world
Copy link

@n3world n3world commented Sep 28, 2022

Invert the extend check in Type::cast so that it is checking if this instance extends wrapper and therefor this can be cast to Wrapper.

Invert the extend check in Type::cast so that it is checking if this
instance extends wrapper and therefor this can be cast to Wrapper.
@@ -556,7 +556,7 @@ class Type {
template <class T, class Clazz>
template<class Wrapper>
Wrapper ObjectWrapper<T, Clazz>::cast() const {
if(!Wrapper::Class::getType()->extends(m_valueType)) {
if(!m_valueType->extends(Wrapper::Class::getType())) {
Copy link
Member

Choose a reason for hiding this comment

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

ObjectWrapper<T, Clazz>::cast() - is an unsafe static cast which allows downcasts to child classes. Thats why we check if Wrapper::Class::getType()->extends(m_valueType).

Copy link
Author

Choose a reason for hiding this comment

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

I thought it was just for type safe casting hence the checks being there. The reason I made this change was so cast could be used in oatpp-protobuf to perform casts from the Void reference to oatpp::Vector<AbstractDynamicObject> for repeated fields. Without this change even though Vector<AbstractDynamicObject> is a parent of DynamicClass there is no clean way to cast from the Void objects to Vector<AbstractDynamicObject> and the same error seen in #595 occurs.

Copy link
Author

Choose a reason for hiding this comment

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

I did try to use assignment copy and played around with that a little but could only seem to get raw static casts to work, which is what is being done in StandardCollection::PolymorphicDispatcher so maybe that is the only answer for now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants