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

TreeNode::setOutput doesn't consider BT::AnyTypeAllowed when checking for variant port type #893

Closed
robin-mueller opened this issue Dec 10, 2024 · 1 comment

Comments

@robin-mueller
Copy link
Contributor

robin-mueller commented Dec 10, 2024

I would like to change this line to also consider BT::AnyTypeAllowed. This would allow the user to correctly allow all types for a specific port.

When using BT::Any instead, the BT::TypeInfo of the port defines the functor for converting from string like here. This essentially breaks the scripting language because BT::convertFromString<BT::Any>() is illegal but will be called internally when a script is evaluated for a variable associated with a BT::Any port (This association is defined during tree initialization to validate types).

Therefore, I suggest to replace

if constexpr(std::is_same_v<BT::Any, T>)
{
  if(config().manifest->ports.at(key).type() != typeid(BT::Any))
  {
    throw LogicError("setOutput<Any> is not allowed, unless the port "
                     "was declared using OutputPort<Any>");
  }
}

with this

if constexpr(std::is_same_v<BT::Any, T>)
{
  const std::type_index type = config().manifest->ports.at(key).type();
  if(type != typeid(BT::Any) && type != typeid(BT::AnyTypeAllowed))
  {
    throw LogicError("setOutput<BT::Any> is not allowed, unless the port "
                     "was declared using OutputPort<BT::Any> or "
                     "OutputPort<BT::AnyTypeAllowed>");
  }
}

from here.

It would be nice if what I'm trying to do here would be possible with BT::Any alone but I guess this requires to dig deep in the type validation and scripting logic.

@facontidavide
Copy link
Collaborator

thanks. i will apply this change

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

No branches or pull requests

2 participants