[IronPython] constructor inheritance not working

Paolo Molaro lupus at ximian.com
Wed Aug 25 12:55:47 CEST 2004


On 08/24/04 Edd Dumbill wrote:
> public class TestCtor {
> 	public int Val;
> 
> 	public TestCtor (int val)
> 	{
> 		Val = val;
> 	}
> 
> 	public TestCtor () : this (5)
> 	{
> 	}
> }
> 
> When the second constructor is called from IronPython, the inherited
> constructor isn't being called, and so Val remains uninitialised.  This
> ctor use is quite a common pattern in Gtk#, which is where I first
> encountered the issue.

As mentioned in another post, it looks like IronPython doesn't select
the best method to invoke, in particular, if it finds a method with more
args first, it will happily call that supplying default arguments for
the missing params. At least this is what it seems from a quick lokk at
the code. So the issue is not that mono doesn't call the inherited ctor,
but that the base ctor is called directly by IronPython.
If you invert the two TestCtor constructors in the source and recompile,
the test runs fine in mono (would be interesting to know if it will work
on the MS runtime, for some reason it hangs for me when running this
sample, so I can't test it myself). There is still a minute chance this
is due to some different behaviour in reflection between mono and MS,
haven't investigated further.

lupus

-- 
-----------------------------------------------------------------
lupus at debian.org                                     debian/rules
lupus at ximian.com                             Monkeys do it better



More information about the Ironpython-users mailing list