]> 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>
Wed, 7 Apr 2021 16:14:16 +0000 (18:14 +0200)
Found by -fsanitize=address

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

index 8e1e25db11fb9146254389c5499eda667fc14dd7..944d6a00a42049bfa7198ea491a60ce56109bddd 100644 (file)
@@ -641,7 +641,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 3454623d29a05063915d4372c10568a1253ad26c..a802bc8fba0ee335963c18500c4bfe851783a549 100644 (file)
@@ -143,6 +143,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..aed1ab3
--- /dev/null
@@ -0,0 +1,29 @@
+[Compact]
+class Foo {
+       public int i = 42;
+       public int j = 23;
+
+       public Foo () {
+               assert (i == 42);
+               j = 23;
+       }
+
+       public Foo.bar () {
+               this ();
+               assert (i == 42);
+               assert (j == 23);
+       }
+}
+
+void main () {
+       {
+               var foo = new Foo ();
+               assert (foo.i == 42);
+               assert (foo.j == 23);
+       }
+       {
+               var foo = new Foo.bar ();
+               assert (foo.i == 42);
+               assert (foo.j == 23);
+       }
+}