]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
Revert "codegen: Handle property initializers of non-gobject classes"
authorRico Tzschichholz <ricotz@ubuntu.com>
Mon, 16 Apr 2018 08:06:23 +0000 (10:06 +0200)
committerRico Tzschichholz <ricotz@ubuntu.com>
Mon, 16 Apr 2018 08:06:23 +0000 (10:06 +0200)
This reverts commit 9b3eedbe81718a7a0bd9e5a97e4796e0eaa65e7f.

codegen/valagobjectmodule.vala
codegen/valagtypemodule.vala
tests/objects/bug701978.vala

index 11aa6e686a23a37d35390b431fdc758e5a06c4d2..82eba077421bfc986e96ec643e69f1e0518ef40e 100644 (file)
@@ -688,6 +688,27 @@ public class Vala.GObjectModule : GTypeModule {
 
                if (is_gobject_property (prop) && prop.parent_symbol is Class) {
                        prop_enum.add_value (new CCodeEnumValue ("%s_PROPERTY".printf (get_ccode_upper_case_name (prop))));
+
+                       if (prop.initializer != null && prop.set_accessor != null && !prop.set_accessor.automatic_body) {
+                               // generate a custom initializer if it couldn't be done at class_init time
+                               bool has_spec_initializer = prop.property_type.data_type is Enum;
+                               if (!has_spec_initializer && prop.property_type.data_type is Struct) {
+                                       var param_spec_func = get_ccode_param_spec_function (prop.property_type.data_type);
+                                       has_spec_initializer = param_spec_func != "g_param_spec_boxed";
+                               }
+                               if (!has_spec_initializer) {
+                                       push_context (instance_init_context);
+
+                                       prop.initializer.emit (this);
+
+                                       var inst_ma = new MemberAccess.simple ("this");
+                                       inst_ma.target_value = new GLibValue (get_data_type_for_symbol ((Class) prop.parent_symbol), new CCodeIdentifier ("self"), true);
+                                       store_property (prop, inst_ma, prop.initializer.target_value);
+
+                                       temp_ref_values.clear ();
+                                       pop_context ();
+                               }
+                       }
                }
        }
 
index c227ac1e7a731a4fe050d024660b10b636203815..daad49cd13b2f6c96e06920a739f5bca20e8ef44 100644 (file)
@@ -2392,40 +2392,6 @@ public class Vala.GTypeModule : GErrorModule {
                        Report.error (prop.source_reference, "Property 'type' not allowed");
                        return;
                }
-
-               if (prop.initializer != null) {
-                       if (cl == null || cl.is_compact) {
-                               Report.warning (prop.source_reference, "Only properties in non-compact classes are allowed to have initializers");
-                       } else if (prop.set_accessor != null && !prop.set_accessor.automatic_body) {
-                               // generate a custom initializer if it couldn't be done at class_init time
-                               bool has_spec_initializer = prop.property_type.data_type is Enum;
-                               if (!has_spec_initializer && prop.property_type.data_type is Struct) {
-                                       var param_spec_func = get_ccode_param_spec_function (prop.property_type.data_type);
-                                       has_spec_initializer = param_spec_func != "g_param_spec_boxed";
-                               }
-                               if (!has_spec_initializer) {
-                                       push_context (instance_init_context);
-
-                                       prop.initializer.emit (this);
-
-                                       var inst_ma = new MemberAccess.simple ("this");
-                                       inst_ma.target_value = new GLibValue (get_data_type_for_symbol (cl), new CCodeIdentifier ("self"), true);
-
-                                       var prop_init_value = (GLibValue) prop.initializer.target_value;
-                                       if (prop_init_value.delegate_target_cvalue == null) {
-                                               prop_init_value.delegate_target_cvalue = new CCodeConstant ("NULL");
-                                       }
-                                       if (prop_init_value.delegate_target_destroy_notify_cvalue == null) {
-                                               prop_init_value.delegate_target_destroy_notify_cvalue = new CCodeConstant ("NULL");
-                                       }
-                                       store_property (prop, inst_ma, prop_init_value);
-
-                                       temp_ref_values.clear ();
-                                       pop_context ();
-                               }
-                       }
-               }
-
                base.visit_property (prop);
        }
 
index aa809c1829ce6de978ff1493f9c168c0ede75bee..22fcfafdde46a74750fe93ec15d13d638009570b 100644 (file)
@@ -16,20 +16,7 @@ public class Bar : Object {
        }
 }
 
-public class Baz {
-       private Foo _foo;
-
-       public Foo foo {
-               get { return _foo; }
-               set { _foo = value; }
-               default = Foo ();
-       }
-}
-
 void main () {
        var bar = new Bar();
        assert (bar.foo.val == 55);
-
-       var baz = new Baz();
-       assert (baz.foo.val == 55);
 }