When wrapping a C++ class hierarchy using two Ruby modules, and the subclass has the same name as the base class but is in a different namespace, the Ruby class information is wrong at runtime. The situation (shortened):
Now, when calling bar() from Ruby, the Ruby class of the returned object is Foo::Sub::Bar, where instead it should be Foo::Bar. The class of subbar() is Foo::Sub::Bar (which is correct):
What's interesting is that the __swigtype__ is correct:
When debugging with gdb, I can see that the entries in swig_types point to the same clientdata struct. So, I assume that somewhere the clientdata is set wrongly.
What's also interesting is that, with -DSWIGRUNTIME_DEBUG, the following cast list is printed for bar (I would expect _p_Foo__Bar to be the first cast in the list here):
SWIG_InitializeModule: type 0 _p_Foo__Bar
SWIG_InitializeModule: cast type _p_Foo__Sub__Bar
SWIG_InitializeModule: cast type _p_Foo__Bar
When changing the class name of Foo::Sub::Bar to Baz, the problem goes away.
Please extract the attached example, build and run it to reproduce the problem.
The version of SWIG is svn trunk 12817.