GNOME Bugzilla – Bug 604590
Assigning to a construct-only property should be an error, not a warning
Last modified: 2009-12-19 11:48:17 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).
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.