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

std.algorithm.each returns a misleading compile error #10170

Open
dlangBugzillaToGithub opened this issue Apr 7, 2016 · 0 comments
Open

std.algorithm.each returns a misleading compile error #10170

dlangBugzillaToGithub opened this issue Apr 7, 2016 · 0 comments

Comments

@dlangBugzillaToGithub
Copy link

trikko (@trikko) reported this on 2016-04-07T15:56:42Z

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

Description

This code:

import std.algorithm : each;

void main()
{

	auto arr = [1,2,3];
	arr.each!(x => writeln(x));	
}

won't compile:

/d768/f609.d(8): Error: template f609.main.each!((x) => writeln(x)).each cannot deduce function from argument types !()(int[]), candidates are:
/opt/compilers/dmd2/include/std/algorithm/iteration.d(875):        f609.main.each!((x) => writeln(x)).each(Range)(Range r) if (isRangeIterable!Range && !isForeachIterable!Range)
/opt/compilers/dmd2/include/std/algorithm/iteration.d(899):        f609.main.each!((x) => writeln(x)).each(Iterable)(Iterable r) if (isForeachIterable!Iterable)

The real problem is that x => writeln(x) doesn't compile because you missed import std.stdio in this case. The same goes if any error exists inside lambda. But error won't give help you that much (in this case error is easy to spot)
@thewilsonator thewilsonator removed OS:Linux Issues specific to Linux Arch:x86_64 Issues specific to x86_64 P4 labels Dec 5, 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