]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
codegen: Propagate default_value_on_error from parent struct
authorSergey Bugaev <bugaevc@gmail.com>
Mon, 28 Apr 2025 07:31:16 +0000 (10:31 +0300)
committerRico Tzschichholz <ricotz@ubuntu.com>
Sun, 11 May 2025 20:04:50 +0000 (22:04 +0200)
Like it's already done for default_value. This in particular should
impact tests/structs/gtype-base-struct.vala when we set the default
values for GLib.Type.

codegen/valaccodeattribute.vala

index 08de1251f9cdc51a19ca2715471b75297733e4ff..187409cca149944e252dae110468b4773a564a2c 100644 (file)
@@ -426,7 +426,7 @@ public class Vala.CCodeAttribute : AttributeCache {
                                        _default_value_on_error = ccode.get_string ("default_value_on_error");
                                }
                                if (_default_value_on_error == null) {
-                                       _default_value_on_error = default_value;
+                                       _default_value_on_error = get_default_default_value_on_error ();
                                }
                        }
                        return _default_value_on_error;
@@ -1470,6 +1470,16 @@ public class Vala.CCodeAttribute : AttributeCache {
                return "";
        }
 
+       private string get_default_default_value_on_error () {
+               if (sym is Struct) {
+                       unowned Struct? base_st = ((Struct) sym).base_struct;
+                       if (base_st != null) {
+                               return get_ccode_default_value_on_error (base_st);
+                       }
+               }
+               return default_value;
+       }
+
        private string get_finish_name_for_basename (string basename) {
                string result = basename;
                if (result.has_suffix ("_async")) {