GNOME Bugzilla – Bug 791785
Property setting issue with inherited classes
Last modified: 2017-12-21 14:18:32 UTC
Created attachment 365745 [details] Reproducible example Something seems to have happened between 0.38.4 and 0.39.2 that's causing issues with setting properties on child classes when inheritance is invovled. It's possible that this only affects structs being passed. See the attached sample code for an example. Under Vala 0.38.4, this produces the expected outcome of "20", under Vala 0.39.2, it seems like the struct is uninitialized and produces an output of "0". If the property is set in the "BaselineFetchJob" constructor after "base" has been called, the property is set correctly. However, this is not ideal as it defeats the point of inheritance. Apologies if this isn't very well explained, my programming terminology isn't brilliant, but hopefully my example will demonstrate the issue.
I tried with a SimpleType struct, an int, and the field in the base class is set correctly. With a Vala struct then the field in the object is not set at all - I'm getting random numbers. So it could be failing when chaining up in the constructor with a struct type as an argument. I've not tried an object instance type. Looking at C code from the following test case: void main () { var initialized_test_struct = IncrementByOneStruct (20); assert_true (initialized_test_struct.value == 21); var test_object = new Test(initialized_test_struct); assert_true (test_object.my_field.value == 21); } public struct IncrementByOneStruct { int value; IncrementByOneStruct (int value) { this.value = value + 1; } } public class BaseTest { public IncrementByOneStruct my_field; BaseTest (IncrementByOneStruct value) { my_field = value; } } public class Test:BaseTest { public Test (IncrementByOneStruct value) { base (value); } } The code generated for the Test constructor shows the temporary variable is assigned to 'value' after the chain up occurs: Test* test_construct (GType object_type, IncrementByOneStruct* value) { Test* self = NULL; IncrementByOneStruct _tmp0_; g_return_val_if_fail (value != NULL, NULL); self = (Test*) base_test_construct (object_type, &_tmp0_); _tmp0_ = *value; return self; }
Created attachment 365806 [details] [review] codegen: Fix chain-up regression with real non-null struct parameters Regression of b9035aaf17a9a97a070812a8ee83251fd3893b1e
Attachment 365806 [details] pushed as 60563fc - codegen: Fix chain-up regression with real non-null struct parameters