Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Misleading error message: Cannot deduce function #10116

Open
dlangBugzillaToGithub opened this issue Feb 23, 2015 · 1 comment
Open

Misleading error message: Cannot deduce function #10116

dlangBugzillaToGithub opened this issue Feb 23, 2015 · 1 comment

Comments

@dlangBugzillaToGithub
Copy link

andre reported this on 2015-02-23T15:55:24Z

Transfered from https://issues.dlang.org/show_bug.cgi?id=14217

CC List

Description

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'
@dlangBugzillaToGithub
Copy link
Author

nick (@ntrel) commented on 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.

@LightBender LightBender removed the P3 label Dec 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants