After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 581362 - base() call in creation method generates incorrect code
base() call in creation method generates incorrect code
Status: RESOLVED FIXED
Product: vala
Classification: Core
Component: Code Generator
0.7.x
Other All
: Normal major
: ---
Assigned To: Vala maintainers
Vala maintainers
: 564449 593467 (view as bug list)
Depends on:
Blocks:
 
 
Reported: 2009-05-04 19:35 UTC by Vlad Grecescu
Modified: 2010-03-22 20:39 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Vlad Grecescu 2009-05-04 19:35:22 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
Comment 1 Jan Hudec 2009-05-06 17:15:32 UTC
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.
Comment 2 Vlad Grecescu 2009-05-06 20:45:54 UTC
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?
Comment 3 Jürg Billeter 2009-08-16 19:59:56 UTC
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.
Comment 4 Jürg Billeter 2010-03-20 14:51:38 UTC
*** Bug 593467 has been marked as a duplicate of this bug. ***
Comment 5 Jürg Billeter 2010-03-22 20:39:44 UTC
*** Bug 564449 has been marked as a duplicate of this bug. ***