[vala] Support initializer list for structs that have a base type



commit 998105936f77997e12593b4f48342469a89c3eb6
Author: Luca Bruno <lucabru src gnome org>
Date:   Thu Feb 9 09:39:10 2012 +0100

    Support initializer list for structs that have a base type
    
    Fixes bug 669580.

 codegen/valaccodebasemodule.vala |    3 +++
 tests/Makefile.am                |    1 +
 tests/structs/bug669580.vala     |   10 ++++++++++
 vala/valainitializerlist.vala    |    3 +++
 4 files changed, 17 insertions(+), 0 deletions(-)
---
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index 9d7395e..866e8b9 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -2313,6 +2313,9 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
 		if (list.target_type.data_type is Struct) {
 			/* initializer is used as struct initializer */
 			var st = (Struct) list.target_type.data_type;
+			while (st.base_struct != null) {
+				st = st.base_struct;
+			}
 
 			if (list.parent_node is Constant || list.parent_node is Field || list.parent_node is InitializerList) {
 				var clist = new CCodeInitializerList ();
diff --git a/tests/Makefile.am b/tests/Makefile.am
index c5248d3..9a64c1d 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -84,6 +84,7 @@ TESTS = \
 	structs/bug660426.vala \
 	structs/bug661945.vala \
 	structs/bug667890.vala \
+	structs/bug669580.vala \
 	delegates/delegates.vala \
 	delegates/bug539166.vala \
 	delegates/bug595610.vala \
diff --git a/tests/structs/bug669580.vala b/tests/structs/bug669580.vala
new file mode 100644
index 0000000..ef1308b
--- /dev/null
+++ b/tests/structs/bug669580.vala
@@ -0,0 +1,10 @@
+struct Foo {
+	int i;
+}
+
+struct Bar : Foo {
+}
+
+void main() {
+	Bar bar = { 0 };
+}
diff --git a/vala/valainitializerlist.vala b/vala/valainitializerlist.vala
index b2350ae..edd9857 100644
--- a/vala/valainitializerlist.vala
+++ b/vala/valainitializerlist.vala
@@ -153,6 +153,9 @@ public class Vala.InitializerList : Expression {
 		} else if (target_type.data_type is Struct) {
 			/* initializer is used as struct initializer */
 			var st = (Struct) target_type.data_type;
+			while (st.base_struct != null) {
+				st = st.base_struct;
+			}
 
 			var field_it = st.get_fields ().iterator ();
 			foreach (Expression e in get_initializers ()) {



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