The following source code doesn't compile because in the lambda 'a.bar' is written instead of 'a.foo'.
import std.algorithm: canFind;
struct A { string foo; }
void main()
{
A[] arr;
arr.canFind!(a => a.bar);
}
It isn't clear from the error message, that the property'bar' is causing the error:
source\app.d(9):
Error: template std.algorithm.canFind cannot deduce function
from argument types !((a) => a.bar)(A[]), candidates are:
C:\D\dmd2\windows\bin\..\..\src\phobos\std\algorithm.d(11266): std.algorithm.canFind(alias pred = "a == b")
I would expect an error message: no property 'bar' for type 'A'
Comment #1 by nick — 2018-06-23T13:52:38Z
Like Issue 13683, this is caused by canFind's template constraint rather than dmd. It could be changed to use a static assert, so that the error mentions that the lambda can't take an A.
Comment #2 by robert.schadek — 2024-12-01T16:23:47Z