}
}
+ 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);
}
}
+ // 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 ();
}
arrays/length-no-int-type.test \
arrays/struct-field-length-cname.vala \
arrays/struct-field-initializer.vala \
+ arrays/struct-initializer-null.vala \
arrays/struct-namespaced-initializer.vala \
arrays/incompatible-integer-elements.test \
arrays/resize.vala \
--- /dev/null
+struct Foo {
+ public unowned string s;
+ public int i;
+}
+
+const Foo[] FOOS = { { "foo", 23 }, {} };
+const Foo[] BARS = { { "bar", 42 }, null };
+
+void main () {
+ Foo[] foos = { { "foo", 23 }, {} };
+ Foo[] bars = { { "bar", 42 }, null };
+}
unowned UnaryExpression? unary = e as UnaryExpression;
if (unary != null && (unary.operator == UnaryOperator.REF || unary.operator == UnaryOperator.OUT)) {
// TODO check type for ref and out expressions
+ } else if (e is NullLiteral && e.target_type != null && e.target_type.is_real_non_null_struct_type ()) {
+ // Allow using null instead of {} to initialize struct
} else if (!e.value_type.compatible (e.target_type)) {
error = true;
e.error = true;