Commit 056daaae authored by Rico Tzschichholz's avatar Rico Tzschichholz

codegen: Pass lambda expression of variable initializer to signal connect

parent 57fa049a
......@@ -595,11 +595,14 @@ public class Vala.GSignalModule : GObjectModule {
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;
......
......@@ -287,6 +287,7 @@ TESTS = \
objects/signals.vala \
objects/signals-delegate.vala \
objects/signals-delegate-parameter.vala \
objects/signals-lambda-delegate.vala \
objects/singleton.vala \
objects/test-025.vala \
objects/test-026.vala \
......
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);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment