GNOME Bugzilla – Bug 624101
In interfaces virtual properties are not hooked up in the generated c code
Last modified: 2018-05-22 13:41:28 UTC
If you have a virtual property in an interface the function implementation is not hooked up in the iface_name_base_init function (virtual methods are, though).
I'm having a similar (possibly the same issue): Let's say I define an interface: public interface Interface { public string foo { get; set; } } And a class that inherits it: public class Class : GLib.Object, Interface { } Let's say I want to find the property for some reason, like this (obj is an instance of Class): var prop = obj.get_class().find_property("foo"); For example I might want to do something like this (I'm just assuming this will compile, but you get the idea...): public GLib.Value get_gvalue(GLib.Object, string prop) { var type = obj.get_class().find_property(prop).value_type; return GLib.Value(type); } While this will work fine for any property contained within a class, it won't work with an interface/mixin, as shown above. The code will compile, but in the first example "type" will be null, and in the second the code will crash when run (for the same reason). I think these are similar issues (possibly the same). frederik on #vala helped me find the potential issue: 03:47 < frederik> nate: i think a problem is that vala doesn't seem to install interface properties via 'g_object_interface_install_property': http://pastebin.com/rgz9Ye7U 03:47 < frederik> http://library.gnome.org/devel/gobject/stable/gobject-The-Base-Object-Type.html#g-object-interface-install-property 03:47 < frederik> http://library.gnome.org/devel/gobject/stable/gobject-The-Base-Object-Type.html#g-object-interface-find-property ... 04:01 < frederik> for a class 'g_object_class_install_property' is called: http://pastebin.com/LRUsDD1k
Here's another symptom of what is probably the same problem. If you try to set any property defined in an interface in Vala code, then GObject reports a warning that the property does not exist. Here's a test program: === test.vala === int global; interface Foo : Object { public int abc { get { return global; } set { global = value; } } } class Bar : Foo, Object { } void main(string[] args) { Bar b = new Bar(); b.abc = 7; debug("abc = %d", b.abc); } === end === $ valac test.vala $ ./test (process:2782): GLib-GObject-WARNING **: g_object_notify: object class `Bar' has no property named `abc' ** (process:2782): DEBUG: test.vala:16: abc = 7 $
With Vala master the sample from https://bugzilla.gnome.org/show_bug.cgi?id=624101#c2 seems to work ok. Could you check whether the other cases are still open?
-- GitLab Migration Automatic Message -- This bug has been migrated to GNOME's GitLab instance and has been closed from further activity. You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.gnome.org/GNOME/vala/issues/119.