]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
codegen: Correctly handle chain up of struct creation methods
authorRico Tzschichholz <ricotz@ubuntu.com>
Sat, 11 Dec 2021 09:34:03 +0000 (10:34 +0100)
committerRico Tzschichholz <ricotz@ubuntu.com>
Sun, 9 Jan 2022 09:11:49 +0000 (10:11 +0100)
Fixes https://gitlab.gnome.org/GNOME/vala/issues/1264

codegen/valaccodebasemodule.vala
codegen/valaccodemethodmodule.vala
tests/chainup/struct-base-foo.vala
tests/chainup/struct-this-foo.vala
vala/valamethodcall.vala
vala/valaobjectcreationexpression.vala

index db66ddb8e92b2685bb50077325508e5069bb7a5e..56a301599499231b70e33cd5e36eacbf985368ee 100644 (file)
@@ -4821,6 +4821,8 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
                                } else if (param != null) {
                                        instance = get_cvalue_ (get_parameter_cvalue (param));
                                }
+                       } else if (expr.is_chainup) {
+                               instance = get_this_cexpression ();
                        } else {
                                var temp_value = create_temp_value (expr.type_reference, true, expr);
                                instance = get_cvalue_ (temp_value);
@@ -4865,7 +4867,11 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
                        }
 
                        if ((st != null && !st.is_simple_type ()) && !(get_ccode_instance_pos (m) < 0)) {
-                               creation_call.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, instance));
+                               if (expr.is_chainup) {
+                                       creation_call.add_argument (instance);
+                               } else {
+                                       creation_call.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, instance));
+                               }
                        } else if (st != null && get_ccode_name (st) == "va_list") {
                                creation_call.add_argument (instance);
                                if (get_ccode_name (m) == "va_start") {
index e2811310834692267ecb80ca5245d20626a27eb2..0648f1483a3f20b6372972813b622f509f87aa6a 100644 (file)
@@ -667,7 +667,7 @@ public abstract class Vala.CCodeMethodModule : CCodeStructModule {
                                                        var vardecl = new CCodeVariableDeclarator ("self", default_value_for_type (creturn_type, true));
                                                        vardecl.init0 = true;
                                                        ccode.add_declaration (get_ccode_name (creturn_type), vardecl);
-                                               } else {
+                                               } else if (!((CreationMethod) m).chain_up) {
                                                        // memset needs string.h
                                                        cfile.add_include ("string.h");
                                                        var czero = new CCodeFunctionCall (new CCodeIdentifier ("memset"));
index 44aeb3bb13a43517db3253f82580963a3d3d7398..b54bd654dc0df13ee7dfa52163f441ab88f7b452 100644 (file)
@@ -15,6 +15,6 @@ public struct Bar : Foo {
 
 void main () {
        var bar = Bar ();
-       //FIXME assert (bar.i == 1);
+       assert (bar.i == 1);
        assert (bar.j == 1);
 }
index c0e53beed93f052516a3037902df5ef4331ba76c..b4b835629e473cd1815cbfef5f1bb7e81e4646c2 100644 (file)
@@ -12,6 +12,6 @@ public struct Foo {
 
 void main () {
        var foo = Foo ();
-       //FIXME assert (foo.i == 1);
+       assert (foo.i == 1);
        assert (foo.j == 1);
 }
index 2abdc74e523d9fff9f1da69f222c4852bff90fb0..c7ace27bcfb2e250fdf96901fcfc0be5b26d09f0 100644 (file)
@@ -315,6 +315,7 @@ public class Vala.MethodCall : Expression {
 
                        var struct_creation_expression = new ObjectCreationExpression ((MemberAccess) call, source_reference);
                        struct_creation_expression.struct_creation = true;
+                       struct_creation_expression.is_chainup = is_chainup;
                        foreach (Expression arg in argument_list) {
                                struct_creation_expression.add_argument (arg);
                        }
index fc6d161a7d775c3369b35421482c7fafb29865dc..e3eda46d6f25742593e341d6ef6917b55e3ae34a 100644 (file)
@@ -53,6 +53,8 @@ public class Vala.ObjectCreationExpression : Expression {
 
        public bool is_yield_expression { get; set; }
 
+       public bool is_chainup { get; set; }
+
        public bool struct_creation { get; set; }
 
        private List<Expression> argument_list = new ArrayList<Expression> ();