Bug 14217 – Misleading error message: Cannot deduce function

Status
NEW
Severity
normal
Priority
P3
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2015-02-23T15:55:24Z
Last change time
2024-12-01T16:23:47Z
Keywords
diagnostic
Assigned to
No Owner
Creator
Andre
See also
https://issues.dlang.org/show_bug.cgi?id=13683, https://issues.dlang.org/show_bug.cgi?id=11907
Moved to GitHub: phobos#10116 →

Comments

Comment #0 by andre — 2015-02-23T15:55:24Z
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
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/phobos/issues/10116 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB