diff options
author | Rico Tzschichholz <ricotz@ubuntu.com> | 2021-12-11 10:34:03 +0100 |
---|---|---|
committer | Rico Tzschichholz <ricotz@ubuntu.com> | 2022-01-09 10:11:49 +0100 |
commit | 2343e3fcd6add34d8ce6e46a1a881661efa2ecab (patch) | |
tree | 674db591a39d209ea891f1810162f4998469afae | |
parent | 0423a6337884a319cafdba369525e406a0e0c822 (diff) | |
download | vala-2343e3fcd6add34d8ce6e46a1a881661efa2ecab.tar.gz |
codegen: Correctly handle chain up of struct creation methods
Fixes https://gitlab.gnome.org/GNOME/vala/issues/1264
-rw-r--r-- | codegen/valaccodebasemodule.vala | 8 | ||||
-rw-r--r-- | codegen/valaccodemethodmodule.vala | 2 | ||||
-rw-r--r-- | tests/chainup/struct-base-foo.vala | 2 | ||||
-rw-r--r-- | tests/chainup/struct-this-foo.vala | 2 | ||||
-rw-r--r-- | vala/valamethodcall.vala | 1 | ||||
-rw-r--r-- | vala/valaobjectcreationexpression.vala | 2 |
6 files changed, 13 insertions, 4 deletions
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala index db66ddb8e..56a301599 100644 --- a/codegen/valaccodebasemodule.vala +++ b/codegen/valaccodebasemodule.vala @@ -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") { diff --git a/codegen/valaccodemethodmodule.vala b/codegen/valaccodemethodmodule.vala index e28113108..0648f1483 100644 --- a/codegen/valaccodemethodmodule.vala +++ b/codegen/valaccodemethodmodule.vala @@ -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")); diff --git a/tests/chainup/struct-base-foo.vala b/tests/chainup/struct-base-foo.vala index 44aeb3bb1..b54bd654d 100644 --- a/tests/chainup/struct-base-foo.vala +++ b/tests/chainup/struct-base-foo.vala @@ -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); } diff --git a/tests/chainup/struct-this-foo.vala b/tests/chainup/struct-this-foo.vala index c0e53beed..b4b835629 100644 --- a/tests/chainup/struct-this-foo.vala +++ b/tests/chainup/struct-this-foo.vala @@ -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); } diff --git a/vala/valamethodcall.vala b/vala/valamethodcall.vala index 2abdc74e5..c7ace27bc 100644 --- a/vala/valamethodcall.vala +++ b/vala/valamethodcall.vala @@ -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); } diff --git a/vala/valaobjectcreationexpression.vala b/vala/valaobjectcreationexpression.vala index fc6d161a7..e3eda46d6 100644 --- a/vala/valaobjectcreationexpression.vala +++ b/vala/valaobjectcreationexpression.vala @@ -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> (); |