[Issue 15893] New: std.algorithm.each returns a misleading compile error
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Thu Apr 7 08:56:42 PDT 2016
https://issues.dlang.org/show_bug.cgi?id=15893
Issue ID: 15893
Summary: std.algorithm.each returns a misleading compile error
Product: D
Version: D2
Hardware: x86_64
OS: Linux
Status: NEW
Severity: enhancement
Priority: P1
Component: phobos
Assignee: nobody at puremagic.com
Reporter: trikko at katamail.com
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)
--
More information about the Digitalmars-d-bugs
mailing list