GNOME Bugzilla – Bug 581362
base() call in creation method generates incorrect code
Last modified: 2010-03-22 20:39:44 UTC
the following code: public class MyVBox : Gtk.VBox { public MyVBox () { base (false, 0); } } fails when running valac --pkg gtk+-2.0 with "undefined reference to `gtk_vbox_construct'". The call should probably be to gtk_vbox_new(). However, without that base() call it compiles fine: public class MyVBox : Gtk.VBox { public MyVBox () { } } (tested with vala 0.7.0 and 0.7.1) This prevents the correct initialization of subclasses (in this case, vbox's homogeneous and spacing can be later set, but in other cases they are construct time only properties) Thanks
It obviously CANNOT be gtk_vbox_new, because gtk_vbox_new allocates new VBox, but you only need to initialize an existing one. In GObject, the constructor -- the instance_init member of GTypeInfo -- does not take any arguments. However, it sees the properties set at "construct" time. So the idea is to set the properties defined by the base class at the begining of your constructor. So the code should go like: public class MyVBox : Gtk.VBox { public MyVBox () { homogenous = false; spacing = 0; } } (I didn't test it though -- it's up to you) The syntax is not explicit about which properties will be set at construct time and which will simply be written afterwards, so there may be some bugs related to the compiler getting it wrong and setting the properties too late.
I understand now that it cannot be gtk_vbox_new but what does this mean? That the base () call is invalid and shouldn't have passed through the lexer or that the vala ccode generator should have done exactly what you describe?
commit 85d4d9b16cb1f00d935cf34a280767200e8cc4b7 Author: Jürg Billeter <j@bitron.ch> Date: Sun Aug 16 21:57:38 2009 +0200 Report error on unsupported constructor chain up Fixes bug 581362.
*** Bug 593467 has been marked as a duplicate of this bug. ***
*** Bug 564449 has been marked as a duplicate of this bug. ***