summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRico Tzschichholz <ricotz@ubuntu.com>2019-01-10 20:02:39 +0100
committerRico Tzschichholz <ricotz@ubuntu.com>2019-01-10 20:15:31 +0100
commit0fcdda740f64c09d49777fa74cac71b983275bdb (patch)
treefae17a3e2a4819537fe7b0062894798ceb5ff585
parent9a7c621d6523191922438f8649490e3a4909760f (diff)
downloadvala-0fcdda740f64c09d49777fa74cac71b983275bdb.tar.gz
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
-rw-r--r--codegen/valaccodestructmodule.vala10
-rw-r--r--tests/Makefile.am1
-rw-r--r--tests/ordering/delegate-struct.vala2
-rw-r--r--tests/ordering/struct-delegate.vala9
4 files changed, 17 insertions, 5 deletions
diff --git a/codegen/valaccodestructmodule.vala b/codegen/valaccodestructmodule.vala
index 0e155f74d..d5db42951 100644
--- a/codegen/valaccodestructmodule.vala
+++ b/codegen/valaccodestructmodule.vala
@@ -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) + "*");
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 364e3b32c..3594ebe3e 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -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 \
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 () {
+}