Issue 15893 - std.algorithm.each returns a misleading compile error
Summary: std.algorithm.each returns a misleading compile error
Status: NEW
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: x86_64 Linux
: P4 enhancement
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-04-07 15:56 UTC by Andrea Fontana
Modified: 2024-12-01 16:26 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Andrea Fontana 2016-04-07 15:56:42 UTC
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)
Comment 1 dlangBugzillaToGithub 2024-12-01 16:26:27 UTC
THIS ISSUE HAS BEEN MOVED TO GITHUB

https://github.com/dlang/phobos/issues/10170

DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB