[vala] Fix nullable struct properties



commit 7cd9bc328dc3ec3b555a6ea9d2562877beef4708
Author: Jürg Billeter <j bitron ch>
Date:   Fri Jan 8 21:22:09 2010 +0100

    Fix nullable struct properties
    
    Fixes bug 606202.

 codegen/valaccodeassignmentmodule.vala   |    2 +-
 codegen/valaccodememberaccessmodule.vala |    2 +-
 tests/Makefile.am                        |    1 +
 tests/structs/bug606202.vala             |   18 ++++++++++++++++++
 4 files changed, 21 insertions(+), 2 deletions(-)
---
diff --git a/codegen/valaccodeassignmentmodule.vala b/codegen/valaccodeassignmentmodule.vala
index 451d411..80be69c 100644
--- a/codegen/valaccodeassignmentmodule.vala
+++ b/codegen/valaccodeassignmentmodule.vala
@@ -55,7 +55,7 @@ internal class Vala.CCodeAssignmentModule : CCodeMemberAccessModule {
 			CCodeExpression cexpr = (CCodeExpression) assignment.right.ccodenode;
 
 			if (!prop.no_accessor_method) {
-				if (prop.property_type.is_real_struct_type ()) {
+				if (prop.property_type.is_real_non_null_struct_type ()) {
 					cexpr = get_address_of_expression (assignment.right, cexpr);
 				}
 			}
diff --git a/codegen/valaccodememberaccessmodule.vala b/codegen/valaccodememberaccessmodule.vala
index 9e242d0..b498440 100644
--- a/codegen/valaccodememberaccessmodule.vala
+++ b/codegen/valaccodememberaccessmodule.vala
@@ -275,7 +275,7 @@ internal class Vala.CCodeMemberAccessModule : CCodeControlFlowModule {
 
 				// Property access to real struct types is handled differently
 				// The value is returned by out parameter
-				if (base_property.property_type.is_real_struct_type ()) {
+				if (base_property.property_type.is_real_non_null_struct_type ()) {
 					var ccomma = new CCodeCommaExpression ();
 					var temp_var = get_temp_variable (base_property.get_accessor.value_type);
 					var ctemp = get_variable_cexpression (temp_var.name);
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 9698cfa..e9628cd 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -43,6 +43,7 @@ TESTS = \
 	structs/bug530605.vala \
 	structs/bug583603.vala \
 	structs/bug595587.vala \
+	structs/bug606202.vala \
 	delegates/delegates.vala \
 	delegates/bug595610.vala \
 	delegates/bug595639.vala \
diff --git a/tests/structs/bug606202.vala b/tests/structs/bug606202.vala
new file mode 100644
index 0000000..78beb5b
--- /dev/null
+++ b/tests/structs/bug606202.vala
@@ -0,0 +1,18 @@
+struct Foo {
+	string s;
+
+	public Foo (string s) {
+		this.s = s;
+	}
+}
+
+class Bar : Object {
+	public Foo? foo { get; set; }
+}
+
+void main () {
+	var bar = new Bar ();
+	var foo = Foo ("hello");
+	bar.foo = foo;
+	assert (bar.foo.s == "hello");
+}



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