[vala/0.50] codegen: Inherit GType from base struct of SimpleType structs
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/0.50] codegen: Inherit GType from base struct of SimpleType structs
- Date: Sun, 14 Mar 2021 15:47:53 +0000 (UTC)
commit 7d8e0fe126e5b211ad9d4c175789957aee47f3f1
Author: Rico Tzschichholz <ricotz ubuntu com>
Date: Fri Mar 5 13:47:28 2021 +0100
codegen: Inherit GType from base struct of SimpleType structs
GValue functions and marshaller type are inherited from base structs
already.
This avoids invalid C code which referenced an unavailable GType.
codegen/valaccodeattribute.vala | 4 +--
tests/Makefile.am | 1 +
tests/structs/gtype-base-struct.vala | 47 ++++++++++++++++++++++++++++++++++++
3 files changed, 50 insertions(+), 2 deletions(-)
---
diff --git a/codegen/valaccodeattribute.vala b/codegen/valaccodeattribute.vala
index dfa03531c..b65eb64b4 100644
--- a/codegen/valaccodeattribute.vala
+++ b/codegen/valaccodeattribute.vala
@@ -1014,8 +1014,8 @@ public class Vala.CCodeAttribute : AttributeCache {
return get_ccode_upper_case_name (sym, "TYPE_");
} else if (sym is Struct) {
unowned Struct st = (Struct) sym;
- if (!get_ccode_has_type_id (st)) {
- unowned Struct? base_struct = st.base_struct;
+ unowned Struct? base_struct = st.base_struct;
+ if (!get_ccode_has_type_id (st) || (base_struct != null &&
base_struct.is_simple_type ())) {
if (base_struct != null) {
return get_ccode_type_id (base_struct);
}
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 44dd22759..2f1755d7c 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -334,6 +334,7 @@ TESTS = \
structs/constructor-wrong-name.test \
structs/default-gtype.vala \
structs/gmutex.vala \
+ structs/gtype-base-struct.vala \
structs/gvalue.vala \
structs/gvalue-implicit-comparison.vala \
structs/simple-type-constructor.vala \
diff --git a/tests/structs/gtype-base-struct.vala b/tests/structs/gtype-base-struct.vala
new file mode 100644
index 000000000..3a4c2b946
--- /dev/null
+++ b/tests/structs/gtype-base-struct.vala
@@ -0,0 +1,47 @@
+struct foo_int : int {}
+struct foo_uint : uint {}
+struct foo_int64 : int64 {}
+struct foo_uint64 : uint64 {}
+struct foo_long : long {}
+struct foo_ulong : ulong {}
+struct foo_bool : bool {}
+struct foo_char : char {}
+struct foo_uchar : uchar {}
+struct foo_float : float {}
+struct foo_double : double {}
+struct foo_gtype : GLib.Type {}
+
+class Foo : Object {
+ public foo_int prop_int { get; set; }
+ public foo_uint prop_uint { get; set; }
+ public foo_int64 prop_int64 { get; set; }
+ public foo_uint64 prop_uint64 { get; set; }
+ public foo_long prop_long { get; set; }
+ public foo_ulong prop_ulong { get; set; }
+ public foo_bool prop_bool { get; set; }
+ public foo_char prop_char { get; set; }
+ public foo_uchar prop_uchar { get; set; }
+ public foo_float prop_float { get; set; }
+ public foo_double prop_double { get; set; }
+ public foo_gtype prop_gtype { get; set; }
+}
+
+void main () {
+ {
+ assert (typeof (foo_int) == GLib.Type.INT);
+ assert (typeof (foo_uint) == GLib.Type.UINT);
+ assert (typeof (foo_int64) == GLib.Type.INT64);
+ assert (typeof (foo_uint64) == GLib.Type.UINT64);
+ assert (typeof (foo_long) == GLib.Type.LONG);
+ assert (typeof (foo_ulong) == GLib.Type.ULONG);
+ assert (typeof (foo_bool) == GLib.Type.BOOLEAN);
+ assert (typeof (foo_char) == GLib.Type.CHAR);
+ assert (typeof (foo_uchar) == GLib.Type.UCHAR);
+ assert (typeof (foo_float) == GLib.Type.FLOAT);
+ assert (typeof (foo_double) == GLib.Type.DOUBLE);
+ assert (typeof (foo_gtype) == typeof (GLib.Type));
+ }
+ {
+ var foo = new Foo ();
+ }
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]