From: Ole André Vadla Ravnås Date: Sat, 22 May 2021 21:37:28 +0000 (+0200) Subject: codegen: Fix support for public fields on GLib.Source subclasses X-Git-Tag: 0.53.1~59 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bf2f5c1ef74f4f242da35f25e28e1669964c8e97;p=thirdparty%2Fvala.git codegen: Fix support for public fields on GLib.Source subclasses --- diff --git a/codegen/valagtypemodule.vala b/codegen/valagtypemodule.vala index 5930fcc74..a54b32619 100644 --- a/codegen/valagtypemodule.vala +++ b/codegen/valagtypemodule.vala @@ -89,7 +89,7 @@ public class Vala.GTypeModule : GErrorModule { decl_space.add_type_declaration (new CCodeNewline ()); } - if (cl.is_compact && cl.base_class != null) { + if (!(!cl.is_compact || cl.base_class == null || compact_class_has_instance_struct_member (cl))) { decl_space.add_type_declaration (new CCodeTypeDefinition (get_ccode_name (cl.base_class), new CCodeVariableDeclarator (get_ccode_name (cl)))); } else { decl_space.add_type_declaration (new CCodeTypeDefinition ("struct _%s".printf (get_ccode_name (cl)), new CCodeVariableDeclarator (get_ccode_name (cl)))); @@ -339,8 +339,7 @@ public class Vala.GTypeModule : GErrorModule { instance_struct.add_field ("int", "dummy"); } - if (!cl.is_compact || cl.base_class == null) { - // derived compact classes do not have a struct + if (!cl.is_compact || cl.base_class == null || compact_class_has_instance_struct_member (cl)) { decl_space.add_type_definition (instance_struct); } diff --git a/tests/objects/gsource.vala b/tests/objects/gsource.vala index cb2543979..753d2c4d9 100644 --- a/tests/objects/gsource.vala +++ b/tests/objects/gsource.vala @@ -13,6 +13,28 @@ class FooSource : Source { } } +class BarSource : Source { + public int custom_timeout; + + public BarSource (int timeout) { + custom_timeout = timeout; + } + + public override bool prepare (out int timeout) { + timeout = custom_timeout; + return false; + } + + public override bool check () { + return false; + } + + public override bool dispatch (SourceFunc? callback) { + return false; + } +} + void main () { var foo = new FooSource (); + var bar = new BarSource (1000); }