string connect_func;
DelegateType? dt = null;
- var p = handler.symbol_reference as Parameter;
- if (p != null) {
- dt = p.variable_type as DelegateType;
+ if (handler.symbol_reference is Variable) {
+ dt = ((Variable) handler.symbol_reference).variable_type as DelegateType;
if (dt != null && !context.experimental) {
- Report.warning (dt.source_reference, "Connecting delegates to signals is experimental");
+ Report.warning (handler.source_reference, "Connecting delegates to signals is experimental");
+ }
+ // Use actual lambda expression if available for proper target/destroy handling
+ if (((Variable) handler.symbol_reference).initializer is LambdaExpression) {
+ handler = ((Variable) handler.symbol_reference).initializer;
}
}
var m = handler.symbol_reference as Method;
--- /dev/null
+class Foo : Object {
+ public signal void bar (string s);
+ public signal void baz (string s);
+}
+
+delegate void FooFunc (Foo foo, string s);
+
+void main () {
+ var foo = new Foo ();
+ ulong bar_id = 0U;
+ ulong baz_id = 0U;
+ {
+ FooFunc callback = (f,s) => {
+ assert (s == "bar" || s == "baz");
+
+ if (s == "bar") {
+ assert (bar_id > 0U);
+ f.disconnect (bar_id);
+ bar_id = 0U;
+ }
+
+ if (s == "baz") {
+ assert (baz_id > 0U);
+ f.disconnect (baz_id);
+ baz_id = 0U;
+ }
+ };
+
+ bar_id = foo.bar.connect (callback);
+ baz_id = foo.baz.connect (callback);
+ }
+ {
+ foo.bar ("bar");
+ assert (bar_id == 0U);
+
+ foo.baz ("baz");
+ assert (baz_id == 0U);
+ }
+}