From: Luca Bruno Date: Sun, 25 Dec 2011 12:43:28 +0000 (+0100) Subject: codegen: Use NULL as default C value for nullable structs X-Git-Tag: 0.15.1~17 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8408602255e71ab582b0f957081fdd0401d5ce12;p=thirdparty%2Fvala.git codegen: Use NULL as default C value for nullable structs Fixes bug 665904. --- diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala index f43ff7226..bdc4dd7d8 100644 --- a/codegen/valaccodebasemodule.vala +++ b/codegen/valaccodebasemodule.vala @@ -5587,7 +5587,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator { public CCodeExpression? default_value_for_type (DataType type, bool initializer_expression) { var st = type.data_type as Struct; var array_type = type as ArrayType; - if (type.data_type != null && get_ccode_default_value (type.data_type) != "") { + if (type.data_type != null && !type.nullable && get_ccode_default_value (type.data_type) != "") { return new CCodeConstant (get_ccode_default_value (type.data_type)); } else if (initializer_expression && !type.nullable && (st != null || (array_type != null && array_type.fixed_length))) { diff --git a/tests/Makefile.am b/tests/Makefile.am index 41760d88b..931db3315 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -59,6 +59,7 @@ TESTS = \ control-flow/switch.vala \ control-flow/sideeffects.vala \ control-flow/bug652549.vala \ + control-flow/bug665904.vala \ enums/enums.vala \ structs/structs.vala \ structs/gvalue.vala \ diff --git a/tests/control-flow/bug665904.vala b/tests/control-flow/bug665904.vala new file mode 100644 index 000000000..58d3c67cd --- /dev/null +++ b/tests/control-flow/bug665904.vala @@ -0,0 +1,6 @@ +void main () { + double?[] array = new double?[] { 3, 3, 3 }; + foreach (var i in array) { + assert (i == 3); + } +}