diff options
author | Rico Tzschichholz <ricotz@ubuntu.com> | 2021-06-06 18:11:02 +0200 |
---|---|---|
committer | Rico Tzschichholz <ricotz@ubuntu.com> | 2021-06-06 19:10:46 +0200 |
commit | 9bd652886ad889213ca7c94a0b846947fdb226d3 (patch) | |
tree | 9b5f608c86a885e2ff68990305b3e805fd40238f /codegen/valaccodebasemodule.vala | |
parent | 0fa66cafcbc17c127b486ba7b5483b1cf350f24c (diff) | |
download | vala-9bd652886ad889213ca7c94a0b846947fdb226d3.tar.gz |
codegen: Allow null to initialize non-null struct inside initializer list
Fixes https://gitlab.gnome.org/GNOME/vala/issues/594
Diffstat (limited to 'codegen/valaccodebasemodule.vala')
-rw-r--r-- | codegen/valaccodebasemodule.vala | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala index a1897e575..b04b5c781 100644 --- a/codegen/valaccodebasemodule.vala +++ b/codegen/valaccodebasemodule.vala @@ -2935,6 +2935,10 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator { } } + if (list.size <= 0) { + clist.append (new CCodeConstant ("0")); + } + if (list.parent_node is Constant || (list.parent_node is Expression && ((Expression) list.parent_node).value_type is ArrayType)) { set_cvalue (list, clist); @@ -4402,6 +4406,14 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator { } } + // Allow null to initialize non-null struct inside initializer list + if (expr is NullLiteral && expr.parent_node is InitializerList + && expr.target_type != null && expr.target_type.is_real_non_null_struct_type ()) { + var clist = new CCodeInitializerList (); + clist.append (new CCodeConstant ("0")); + set_cvalue (expr, new CCodeCastExpression (clist, get_ccode_name (expr.target_type.type_symbol))); + } + if (!(expr.value_type is ValueType && !expr.value_type.nullable)) { ((GLibValue) expr.target_value).non_null = expr.is_non_null (); } |