GNOME Bugzilla – Bug 604781
Variables of delegate type cannot be connected to signals
Last modified: 2018-02-13 22:10:44 UTC
Created attachment 149879 [details] Connecting signal handler gives more-or-less unexpected error Trying to use a variable of a delegate type as opposed to a function, method or lambda as the argument to a signal's connect() call causes an error like error: Argument 1: Cannot convert from `SignalHandler' to `Foo.sig'
Duplicate of 624902?
*** Bug 624902 has been marked as a duplicate of this bug. ***
(In reply to Benjamin Herr from comment #0) > Trying to use a variable of a delegate type as opposed to a function, method > or lambda as the argument to a signal's connect() call causes an error like > > error: Argument 1: Cannot convert from `SignalHandler' to `Foo.sig' This error no longer occurs when compiled with 0.39.5. The given sample gives the error "Access to private member `Foo.sig' denied", but the following code compiles and runs: class Foo { internal signal void sig (); } delegate void SignalHandler (); void main () { Foo f = new Foo (); SignalHandler h = () => { print ("signal handler 'h' called\n"); }; f.sig.connect (h); f.sig (); } I assume this was fixed by https://bugzilla.gnome.org/show_bug.cgi?id=787521 There is a Vala warning though: "connect_delegate_to_signal.vala:10.18-10.18: warning: copying delegates is not supported" There is also a C warning: connect_delegate_to_signal.vala.c:44:1: warning: parameter names (without types) in function declaration typedef void (*sig(null)) (void* user_data);
> There is also a C warning: > connect_delegate_to_signal.vala.c:44:1: warning: parameter names (without > types) in function declaration > typedef void (*sig(null)) (void* user_data); This was fixed in https://git.gnome.org/browse/vala/commit/?id=26ddc749ed5dc9d5953ce5e17eeab496e8ee467d
*** This bug has been marked as a duplicate of bug 787521 ***