]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
Support initializer list for structs that have a base type
authorLuca Bruno <lucabru@src.gnome.org>
Thu, 9 Feb 2012 08:39:10 +0000 (09:39 +0100)
committerLuca Bruno <lucabru@src.gnome.org>
Thu, 9 Feb 2012 08:59:46 +0000 (09:59 +0100)
Fixes bug 669580.

codegen/valaccodebasemodule.vala
tests/Makefile.am
tests/structs/bug669580.vala [new file with mode: 0644]
vala/valainitializerlist.vala

index 9d7395ed64f1698bafc0c17df59a1372f4d9e1c0..866e8b9e278c90a3fe4014e8c586b81a33810081 100644 (file)
@@ -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 ();
index c5248d36df340866be65a266a75ea28e15e4a8b3..9a64c1d5e6e80fe66871195e4a6cd2c1a76badc9 100644 (file)
@@ -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 (file)
index 0000000..ef1308b
--- /dev/null
@@ -0,0 +1,10 @@
+struct Foo {
+       int i;
+}
+
+struct Bar : Foo {
+}
+
+void main() {
+       Bar bar = { 0 };
+}
index b2350aee64239b59a9285021b3736c82f8d84d82..edd98570c54be537bf979a3b95da38d3cee05d97 100644 (file)
@@ -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 ()) {