From bf2f5c1ef74f4f242da35f25e28e1669964c8e97 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Ole=20Andr=C3=A9=20Vadla=20Ravn=C3=A5s?= Date: Sat, 22 May 2021 23:37:28 +0200 Subject: [PATCH] codegen: Fix support for public fields on GLib.Source subclasses --- codegen/valagtypemodule.vala | 5 ++--- tests/objects/gsource.vala | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+), 3 deletions(-) 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); } -- 2.47.3