[vala/staging] codegen: Don't call *_instance_init() in compact class chainup



commit 50cbf91db95864299a069d5dba35d8b7f7199941
Author: Rico Tzschichholz <ricotz ubuntu com>
Date:   Wed Apr 7 18:14:16 2021 +0200

    codegen: Don't call *_instance_init() in compact class chainup
    
    Found by -fsanitize=address

 codegen/valaccodemethodmodule.vala    |  2 +-
 tests/Makefile.am                     |  1 +
 tests/chainup/class-compact-this.vala | 29 +++++++++++++++++++++++++++++
 3 files changed, 31 insertions(+), 1 deletion(-)
---
diff --git a/codegen/valaccodemethodmodule.vala b/codegen/valaccodemethodmodule.vala
index 8e1e25db1..944d6a00a 100644
--- a/codegen/valaccodemethodmodule.vala
+++ b/codegen/valaccodemethodmodule.vala
@@ -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) {
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 3454623d2..a802bc8fb 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -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
index 000000000..aed1ab3fe
--- /dev/null
+++ b/tests/chainup/class-compact-this.vala
@@ -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);
+       }
+}


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]