[vala] codegen: Use NULL as default C value for nullable structs



commit 8408602255e71ab582b0f957081fdd0401d5ce12
Author: Luca Bruno <lucabru src gnome org>
Date:   Sun Dec 25 13:43:28 2011 +0100

    codegen: Use NULL as default C value for nullable structs
    
    Fixes bug 665904.

 codegen/valaccodebasemodule.vala  |    2 +-
 tests/Makefile.am                 |    1 +
 tests/control-flow/bug665904.vala |    6 ++++++
 3 files changed, 8 insertions(+), 1 deletions(-)
---
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index f43ff72..bdc4dd7 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 41760d8..931db33 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 0000000..58d3c67
--- /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);
+	}
+}



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]