Comment #0 by bearophile_hugs — 2013-07-10T17:36:48Z
This is wrong code:
void foo(int function(int) f) {}
void main() {
foo(x => 0); // OK
foo(x => 0.0); // Error
foo((x, y) => 0); // Error
}
DMD 2.064alpha gives:
test.d(4): Error: function test.foo (int function(int) f) is not callable using argument types (void)
test.d(5): Error: function test.foo (int function(int) f) is not callable using argument types (void)
I suggest to try to generate better error messages here, that better explain the problem to the programmer.
Comment #1 by nick — 2023-02-01T22:07:42Z
It now also prints e.g.:
badlambda.d(4): cannot pass argument `__lambda2` of type `void` to parameter `int function(int) f`
It would be nice if it said:
(4): Error: lambda returns `double`, expected `int`
(5): Error: lambda does not accept arguments `(int)`
Comment #2 by dlang-bot — 2023-08-19T15:18:18Z
@ntrel created dlang/dmd pull request #15544 "Fix Issue 10602 - Error should state why wrong template lambda doesn'…" fixing this issue:
- Fix Issue 10602 - Error should state why wrong template lambda doesn't match expected function type
https://github.com/dlang/dmd/pull/15544
Comment #3 by robert.schadek — 2024-12-13T18:09:07Z