www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 15893] New: std.algorithm.each returns a misleading compile


          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 puremagic.com
          Reporter: trikko 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:
f609.main.each!((x) => writeln(x)).each(Range)(Range r) if
(isRangeIterable!Range && !isForeachIterable!Range)
f609.main.each!((x) => writeln(x)).each(Iterable)(Iterable r) if

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)

Apr 07 2016