[vala/0.40] codegen: Emit struct declaration typedef before resolving its fields



commit 1cea4a11e7a80ff63c82bdd0e0544de2ce09423f
Author: Rico Tzschichholz <ricotz ubuntu com>
Date:   Thu Jan 10 20:02:39 2019 +0100

    codegen: Emit struct declaration typedef before resolving its fields
    
    This a regression when compiling a circular dependency of delegates with
    structs.
    
    Regression of 7adb3a45bb8d663c0cfca55af26b7e6f7292b14a
    
    See https://gitlab.gnome.org/GNOME/vala/issues/318

 codegen/valaccodestructmodule.vala  | 10 ++++++----
 tests/Makefile.am                   |  1 +
 tests/ordering/delegate-struct.vala |  2 +-
 tests/ordering/struct-delegate.vala |  9 +++++++++
 4 files changed, 17 insertions(+), 5 deletions(-)
---
diff --git a/codegen/valaccodestructmodule.vala b/codegen/valaccodestructmodule.vala
index 0f675f76e..003467bdd 100644
--- a/codegen/valaccodestructmodule.vala
+++ b/codegen/valaccodestructmodule.vala
@@ -64,6 +64,12 @@ public abstract class Vala.CCodeStructModule : CCodeBaseModule {
                        decl_space.add_type_member_declaration (type_fun.get_declaration ());
                }
 
+               if (st.base_struct == null) {
+                       decl_space.add_type_declaration (new CCodeTypeDefinition ("struct _%s".printf 
(get_ccode_name (st)), new CCodeVariableDeclarator (get_ccode_name (st))));
+               } else {
+                       decl_space.add_type_declaration (new CCodeTypeDefinition (get_ccode_name 
(st.base_struct), new CCodeVariableDeclarator (get_ccode_name (st))));
+               }
+
                var instance_struct = new CCodeStruct ("_%s".printf (get_ccode_name (st)));
                instance_struct.modifiers |= (st.version.deprecated ? CCodeModifiers.DEPRECATED : 0);
 
@@ -107,11 +113,7 @@ public abstract class Vala.CCodeStructModule : CCodeBaseModule {
                }
 
                if (st.base_struct == null) {
-                       decl_space.add_type_declaration (new CCodeTypeDefinition ("struct _%s".printf 
(get_ccode_name (st)), new CCodeVariableDeclarator (get_ccode_name (st))));
-
                        decl_space.add_type_definition (instance_struct);
-               } else {
-                       decl_space.add_type_declaration (new CCodeTypeDefinition (get_ccode_name 
(st.base_struct), new CCodeVariableDeclarator (get_ccode_name (st))));
                }
 
                var function = new CCodeFunction (get_ccode_dup_function (st), get_ccode_name (st) + "*");
diff --git a/tests/Makefile.am b/tests/Makefile.am
index fcd519f6a..08260b05e 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -501,6 +501,7 @@ TESTS = \
        ordering/delegate-enum.vala \
        ordering/delegate-interface.vala \
        ordering/delegate-struct.vala \
+       ordering/struct-delegate.vala \
        semantic/array-stacked.test \
        semantic/array-incompatible-initializer.test \
        semantic/array-incompatible-initializer2.test \
diff --git a/tests/ordering/delegate-struct.vala b/tests/ordering/delegate-struct.vala
index 3898423fc..8da5f895a 100644
--- a/tests/ordering/delegate-struct.vala
+++ b/tests/ordering/delegate-struct.vala
@@ -2,7 +2,7 @@
 delegate Foo Func (Foo p);
 
 struct Foo {
-       public int i;
+       public Func f;
 }
 
 void main () {
diff --git a/tests/ordering/struct-delegate.vala b/tests/ordering/struct-delegate.vala
new file mode 100644
index 000000000..e58fb5803
--- /dev/null
+++ b/tests/ordering/struct-delegate.vala
@@ -0,0 +1,9 @@
+public struct Foo {
+       public unowned Func func;
+}
+
+[CCode (has_target = false)]
+public delegate int Func (Foo foo);
+
+void main () {
+}


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