February 22, 2019
https://issues.dlang.org/show_bug.cgi?id=19692

          Issue ID: 19692
           Summary: std.algorithm errors are useless for syntax errors in
                    templated arguments
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: dmd
          Assignee: nobody@puremagic.com
          Reporter: default_357-line@yahoo.de

Consider this code:

import std.algorithm;

void foo(T)(int i) { this.does.not.compile; }

void main() {
    [2, 3, 4].each!foo;
}

foo() is clearly not valid code. However, the error DMD returns is something about "each cannot deduce function from argument types."

each() checks if its lambda argument matches the range we're giving it. However, it does this check using __traits(compiles). __traits(compiles) however does not just check whether the argument is sensible on the face of it, ie. whether foo can be called with an int, but also suppresses errors *inside* foo.

As a result, the error DMD outputs is near completely useless.

A possible solution may be a new traits: __traits(shallowCompiles, ...), that would check whether the expression "itself" compiled, ie. whether function arguments matched, templates could instantiate, etc., but would *not* suppress errors inside function bodies instantiated incidentally underneath the expression.

See also https://issues.dlang.org/show_bug.cgi?id=19448 for a different approach.

--