]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
codegen: Use NULL as default C value for nullable structs
authorLuca Bruno <lucabru@src.gnome.org>
Sun, 25 Dec 2011 12:43:28 +0000 (13:43 +0100)
committerLuca Bruno <lucabru@src.gnome.org>
Mon, 23 Jan 2012 12:03:46 +0000 (13:03 +0100)
Fixes bug 665904.

codegen/valaccodebasemodule.vala
tests/Makefile.am
tests/control-flow/bug665904.vala [new file with mode: 0644]

index f43ff7226c0baebcfc3e36ab5a69d2e7327b4ede..bdc4dd7d830237871fc583d382f71037a8345ce8 100644 (file)
@@ -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))) {
index 41760d88b7b2a86422ce9dd3fb5b22e1939c4ff3..931db331573046b8f8f92a23be5d64f0b28296bb 100644 (file)
@@ -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 (file)
index 0000000..58d3c67
--- /dev/null
@@ -0,0 +1,6 @@
+void main () {
+       double?[] array = new double?[] { 3, 3, 3 };
+       foreach (var i in array) {
+               assert (i == 3);
+       }
+}