When passing a lambda instead of a delegate to connect, it causes the app to segfault.
Tested with DMD 2.085.1.
Here's the most basic sample app that will reproduce the issue:
==========
import std.signals;
import std.stdio;
class Test
{
mixin Signal!(int);
void run ()
{
emit (1);
}
}
class Tester
{
void initialize ()
{
Test test = new Test ();
test.connect ((int a) => trigger (a));
}
void trigger (int a)
{
writeln (a);
}
}
void main ()
{
Tester t = new Tester ();
t.initialize ();
}
==========
Comment #1 by Ajieskola — 2021-06-07T13:22:26Z
Lambda is a delegate in this context. I'm testing with v2.096.0 release canditate and latest Phobos.
This bug does not trigger only with lambda, it triggers with any delegate that is not a class member function.
The documentation does warn that the delegates must be class delegates, but it does not say that that they must be member function pointers. This needs to be clarified, or preferably it should be made to work with non-member-function delegates too.
Comment #2 by dlang-bot — 2021-06-07T13:59:02Z
@dukc created dlang/phobos pull request #8137 "Issue 19842 - only class member functions must be used be used as slots" mentioning this issue:
- Issue 19842 - only class member functions must be used be used as slots
https://github.com/dlang/phobos/pull/8137
Comment #3 by dlang-bot — 2021-06-08T12:32:38Z
@dukc created dlang/phobos pull request #8139 "Issue 19842 - only class member functions must be used be used as slots" mentioning this issue:
- Issue 19842 - only class member functions must be used be used as slots
https://github.com/dlang/phobos/pull/8139
Comment #4 by dlang-bot — 2021-06-08T12:34:02Z
@dukc created dlang/phobos pull request #8140 "Issue 19842 - only class member functions must be used be used as slots" mentioning this issue:
- Issue 19842 - only class member functions must be used be used as slots
https://github.com/dlang/phobos/pull/8140
Comment #5 by dlang-bot — 2021-07-13T10:33:44Z
dlang/phobos pull request #8140 "Issue 19842 - only class member functions must be used be used as slots" was merged into stable:
- 235d3ba9bedf8cd7a9f697231b03f37bac9fd7d3 by Ate Eskola:
Issue 19842 - only class member functions must be used be used as slots
https://github.com/dlang/phobos/pull/8140
Comment #6 by dlang-bot — 2021-07-20T08:54:53Z
@MartinNowak created dlang/phobos pull request #8172 "merge stable" mentioning this issue:
- Issue 19842 - only class member functions must be used be used as slots
https://github.com/dlang/phobos/pull/8172
Comment #7 by dlang-bot — 2021-07-23T06:23:41Z
dlang/phobos pull request #8172 "merge stable" was merged into master:
- 06983381cf824cfae7b8a77d29b0b2fa8fe13c6f by Ate Eskola:
Issue 19842 - only class member functions must be used be used as slots
https://github.com/dlang/phobos/pull/8172
Comment #8 by Ajieskola — 2021-08-25T13:41:01Z
The documetation is now clarified, but it still would be a nice plus for the slot to accept any delegate of the correct type. I changed the severity to enhancement.
Comment #9 by robert.schadek — 2024-12-01T16:34:58Z