ros / genmsg

Standalone Python library for generating ROS message and service data structures for various languages
http://wiki.ros.org/genmsg
29 stars 74 forks source link

Duplicate constants should not be allowed #78

Closed furtypajohn closed 5 years ago

furtypajohn commented 6 years ago

Message generation currently allows a message that contains duplicate constants to succeed through generation. For example:

TestConstant.msg:

uint8 MY_CONSTANT = 0
uint8 MY_CONSTANT = 0

Would succeed and generate the following struct:

template <class ContainerAllocator>
struct TestConstant_
{
  typedef TestConstant_<ContainerAllocator> Type;
  TestConstant_() {}
  TestConstant_(const ContainerAllocator& _alloc) { (void)_alloc; }
  enum { MY_CONSTANT = 0u };
  enum { MY_CONSTANT = 0u };
  typedef boost::shared_ptr< ::test_messages::TestConstant_<ContainerAllocator> > Ptr;
  typedef boost::shared_ptr< ::test_messages::TestConstant_<ContainerAllocator> const> ConstPtr;
}; // struct TestConstant_

Which declares two enums named MY_CONSTANT. This will not compile and because of this it should be caught earlier in the process to alert users that they have an error.

Any constant that is defined more than once (even if it has the same value) should likely result in an error alerting the user that they're doing something wrong.

tfoote commented 6 years ago

That would be a better behavior for the user. We're not going to have time to work on it but we'd happily review a contribution along these lines.

dirk-thomas commented 5 years ago

Closing due to inactivity.