GNOME Bugzilla – Bug 615979
Delegate type conversion failure when missing extraneous "static" keyword
Last modified: 2018-05-22 13:33:42 UTC
With the following setup, valac fails to automatically convert get_contacts_by_handle_cb() to ConnectionContactsByHandleCb. If I add the "static" keyword to the declaration of get_contacts_by_handle_cb(), then the conversion works as expected. ============================= .vapi file ============================= public delegate void ConnectionContactsByHandleCb (Tp.Connection connection, uint n_contacts, Tp.Contact[] contacts, uint n_failed, Tp.Handle[] failed, GLib.Error error, void* user_data, GLib.Object weak_object); ============================= Source file ============================= using GLib; using Gee; using Tp.Individual; using Tp.Channel; using Tp.ConnectionContactsByHandleCb; using Tp.Contact; using Tp.ContactFeature; using Tp.Handle; using Tp.Account; using Tp.AccountManager; using Tp.Lowlevel; ... private void get_contacts_by_handle_cb (Tp.Connection connection, uint n_contacts, Tp.Contact[] contacts, uint n_failed, Tp.Handle[] failed, GLib.Error error, void* user_data, GLib.Object weak_object) { ... } ... this.conn.get_contacts_by_handle (handles_array_length, handles_array, features.length, features, this.get_contacts_by_handle_cb, null, null, this.conn); ============================= Build Error ============================= make[2]: *** [telepathy-people.vala.stamp] Error 1 make[2]: *** Waiting for unfinished jobs.... persona-store.vala:105.33-105.62: error: Argument 5: Cannot convert from `Tp.PersonaStore.get_contacts_by_handle_cb' to `Tp.ConnectionContactsByHandleCb' this.get_contacts_by_handle_cb, null, null, ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Confirming. This is pretty annoying when a callback needs access to the class variables. A work-around is indeed to declare the callback as `static` and pass `this` with the user_data.
-- 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/89.