Issue 14217 - Misleading error message: Cannot deduce function
Summary: Misleading error message: Cannot deduce function
Status: NEW
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: All All
: P3 normal
Assignee: No Owner
URL:
Keywords: diagnostic
Depends on:
Blocks:
 
Reported: 2015-02-23 15:55 UTC by Andre
Modified: 2024-12-01 16:23 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Andre 2015-02-23 15:55:24 UTC
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 Nick Treleaven 2018-06-23 13:52:38 UTC
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 dlangBugzillaToGithub 2024-12-01 16:23:47 UTC
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