Comment #0 by andrej.mitrovich — 2023-06-15T17:12:07Z
DMD 2.102.0
-----
module test;
void call(void delegate(int i) const cb) {
cb(42);
}
struct C {
void callback(int i) const { }
}
void main() {
C c;
call(some_int => c.callback(some_int));
}
-----
$ dmd test.d
> test.d(13): Error: function `test.call(void delegate(int i) const cb)` is not callable using argument types `(void)
> test.d(13): cannot pass argument `__lambda2` of type `void` to parameter `void delegate(int i) const cb`
Commenting out `const` from both the parameter and the ballback function fixes the issue.
Another workaround is to explicitly specify the callback type at the call site:
-----
// Works with `const` with the example above
call((int some_int) const => c.callback(some_int));
-----
But the compiler should be able to derive this on its own.
This workaround also works, where the type is omitted:
-----
call((some_int) const => c.callback(some_int));
-----
Comment #1 by robert.schadek — 2024-12-13T19:29:40Z