Bug 15893 – std.algorithm.each returns a misleading compile error

Status
NEW
Severity
enhancement
Priority
P4
Component
phobos
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2016-04-07T15:56:42Z
Last change time
2024-12-01T16:26:27Z
Assigned to
No Owner
Creator
Andrea Fontana
Moved to GitHub: phobos#10170 →

Comments

Comment #0 by trikko — 2016-04-07T15:56:42Z
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 by robert.schadek — 2024-12-01T16:26:27Z
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