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 604590 - Assigning to a construct-only property should be an error, not a warning
Assigning to a construct-only property should be an error, not a warning
Status: RESOLVED FIXED
Product: vala
Classification: Core
Component: Code Generator: GObject
0.7.x
Other Linux
: Normal normal
: ---
Assigned To: Vala maintainers
Vala maintainers
Depends on:
Blocks:
 
 
Reported: 2009-12-15 00:18 UTC by Darren Warner
Modified: 2009-12-19 11:48 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Darren Warner 2009-12-15 00:18:56 UTC
The following code produces the warning "foobar.vala:11.3-11.7: warning: assigning to construct-only properties is deprecated, use Object (property: value) constructor chain up":

public class Foo : GLib.Object {
    public int a { get; construct; }
}

public class Bar : GLib.Object {
    private Foo foo;

    public Bar() {
        foo = new Foo();
        foo.a = 2;
    }
}

However it produces the following, invalid, C code ('self' is used before it is assigned to):

Bar* bar_construct (GType object_type) {
        GParameter * __params;
        GParameter * __params_it;
	Foo* _tmp0_;
	Bar * self;
        __params = g_new0 (GParameter, 1);
        __params_it = __params;
        self->priv->foo = (_tmp0_ = foo_new (), _g_object_unref0 (self->priv->foo), _tmp0_);
	__params_it->name = "a";
	g_value_init (&__params_it->value, G_TYPE_INT);
        g_value_set_int (&__params_it->value, 2);
        __params_it++;
        self = g_object_newv (object_type, __params_it - __params, __params);
        ...

My understanding of the 'construct' keyword is that the property should not be assigned to after the object has been created, thus the warning should actually be an error to prevent any code from being generated (and resulting in a segv crash at runtime).
Comment 1 Jürg Billeter 2009-12-19 11:48:17 UTC
commit a3de5acd943b6b971b546293be062962517e70f3
Author: Jürg Billeter <j@bitron.ch>
Date:   Sat Dec 19 12:46:15 2009 +0100

    Do not allow assigning to construct-only properties of foreign objects
    
    Fixes bug 604590.