Skip to content

Commit 42b1d80

Browse files
committed
Allow port type mismatch if convertible via base class chain
Adds support for polymorphic upcasting by checking if the previous type is included in the base_chain of the current port during blackboard type consistency checks.
1 parent 12c1377 commit 42b1d80

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/xml_parsing.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -825,10 +825,19 @@ TreeNode::Ptr XMLParser::PImpl::createNodeFromXML(const XMLElement* element,
825825
if(auto prev_info = blackboard->entryInfo(port_key))
826826
{
827827
// Check consistency of types.
828-
bool const port_type_mismatch =
828+
bool port_type_mismatch =
829829
(prev_info->isStronglyTyped() && port_info.isStronglyTyped() &&
830830
prev_info->type() != port_info.type());
831831

832+
// allow mismatch if the previous type appears in the base_chain
833+
// of the current port (i.e., valid polymorphic upcast)
834+
if(port_type_mismatch && !prev_info->baseChain().empty() &&
835+
!port_info.baseChain().empty() &&
836+
prev_info->isConvertibleFrom(port_info.baseChain()[0]))
837+
{
838+
port_type_mismatch = false;
839+
}
840+
832841
// special case related to convertFromString
833842
bool const string_input = (prev_info->type() == typeid(std::string));
834843

0 commit comments

Comments
 (0)