]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
codegen: Don't call *_instance_init() in compact class chainup
authorRico Tzschichholz <ricotz@ubuntu.com>
Wed, 7 Apr 2021 16:14:16 +0000 (18:14 +0200)
committerRico Tzschichholz <ricotz@ubuntu.com>
Thu, 8 Apr 2021 07:28:38 +0000 (09:28 +0200)
Found by -fsanitize=address

codegen/valaccodemethodmodule.vala
tests/Makefile.am
tests/chainup/class-compact-this.vala [new file with mode: 0644]

index 3c26c198eeea49b893a6dc48fd2346a28a4a127c..3dbc02b528cc700063cc64c74e4409d80a70e140 100644 (file)
@@ -645,7 +645,7 @@ public abstract class Vala.CCodeMethodModule : CCodeStructModule {
                                                        ccode.add_assignment (get_this_cexpression (), ccall);
                                                }
 
-                                               if (cl.base_class == null) {
+                                               if (cl.base_class == null && !(((CreationMethod) m).chain_up && cl.is_compact)) {
                                                        var cinitcall = new CCodeFunctionCall (new CCodeIdentifier ("%s_instance_init".printf (get_ccode_lower_case_name (cl, null))));
                                                        cinitcall.add_argument (get_this_cexpression ());
                                                        if (!cl.is_compact) {
index 78e287572f90837e2de633ebd0c72f3962a4b855..f0823d83e53e84980b824e718f3c112845aa270c 100644 (file)
@@ -142,6 +142,7 @@ TESTS = \
        chainup/class-base.vala \
        chainup/class-base-foo.vala \
        chainup/class-compact-base.vala \
+       chainup/class-compact-this.vala \
        chainup/class-object.vala \
        chainup/class-this.vala \
        chainup/class-this-foo.vala \
diff --git a/tests/chainup/class-compact-this.vala b/tests/chainup/class-compact-this.vala
new file mode 100644 (file)
index 0000000..3ace7a7
--- /dev/null
@@ -0,0 +1,34 @@
+[Compact]
+class Foo {
+       public string s = "foo";
+       public int i = 42;
+       public int j;
+
+       public Foo () {
+               assert (s == "foo");
+               assert (i == 42);
+               j = 23;
+       }
+
+       public Foo.bar () {
+               this ();
+               assert (s == "foo");
+               assert (i == 42);
+               assert (j == 23);
+       }
+}
+
+void main () {
+       {
+               var foo = new Foo ();
+               assert (foo.s == "foo");
+               assert (foo.i == 42);
+               assert (foo.j == 23);
+       }
+       {
+               var foo = new Foo.bar ();
+               assert (foo.s == "foo");
+               assert (foo.i == 42);
+               assert (foo.j == 23);
+       }
+}