]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
codegen: Emit struct declaration typedef before resolving its fields
authorRico Tzschichholz <ricotz@ubuntu.com>
Thu, 10 Jan 2019 19:02:39 +0000 (20:02 +0100)
committerRico Tzschichholz <ricotz@ubuntu.com>
Thu, 10 Jan 2019 19:15:31 +0000 (20:15 +0100)
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
tests/Makefile.am
tests/ordering/delegate-struct.vala
tests/ordering/struct-delegate.vala [new file with mode: 0644]

index 0e155f74d3f85a2ccc7037ad59d9338a86119d75..d5db42951ffdee4f0a9c6f80dfd7d31ab4736305 100644 (file)
@@ -66,6 +66,12 @@ 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))));
+               } 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);
 
@@ -109,11 +115,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) + "*");
index 364e3b32c6da0d672263b7467a9c9c86067e2e8f..3594ebe3e055a59924fc17b835dadfa8a018a809 100644 (file)
@@ -538,6 +538,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 \
index 3898423fc31cce1ec2ba7da94e5d782e8b252223..8da5f895a05bdaca96c58e9b3463d444b2beaccd 100644 (file)
@@ -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 (file)
index 0000000..e58fb58
--- /dev/null
@@ -0,0 +1,9 @@
+public struct Foo {
+       public unowned Func func;
+}
+
+[CCode (has_target = false)]
+public delegate int Func (Foo foo);
+
+void main () {
+}