[vala/staging] codegen: Emit struct declaration typedef before resolving its fields
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/staging] codegen: Emit struct declaration typedef before resolving its fields
- Date: Thu, 10 Jan 2019 19:15:58 +0000 (UTC)
commit 0fcdda740f64c09d49777fa74cac71b983275bdb
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 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 () {
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]