May 06, 2023
https://issues.dlang.org/show_bug.cgi?id=23897

          Issue ID: 23897
           Summary: Bad diagnostic "none of the overloads of template" for
                    lamdba
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Keywords: diagnostic
          Severity: regression
          Priority: P4
         Component: dmd
          Assignee: nobody@puremagic.com
          Reporter: dlang-bugzilla@thecybershadow.net

/////////// test.d ///////////
void main()
{
    alias f = (a, b) => a + b;
    f(1);
}
//////////////////////////////

Since 2.099.0, the above fails to compile with:

test.d(4): Error: none of the overloads of template `D main.__lambda1` are
callable using argument types `!()(int)`
test.d(3):        Candidate is: `__lambda1`

There are two problems here:

1. There are no overloads; any overloads here were fabricated by the compiler. These internal changes should be hidden from the user.

2. The diagnostic is not very helpful in identifying the problem. It does not print any information about the template whose arguments are not being matched.

If we rewrite the program to use a more backwards compatible syntax:

//////////////////// test2.d ///////////////////
template Identity(T...) { alias T[0] Identity; }

void main()
{
    alias Identity!((a, b) { return a + b; }) f;
    f(1);
}
////////////////////////////////////////////////

then we see older compilers emit a more useful error message. 2.064 produces:

test2.d(6): Error: template D main.__lambda1 does not match any function
template declaration. Candidates are:
test2.d(5):        test2.main.__lambda1(__T1, __T2)(a, b)
test2.d(6): Error: template test2.main.__lambda1(__T1, __T2)(a, b) cannot
deduce template function from argument types !()(int)

Especially the last line is very useful, and is missing entirely from new compilers.

Last line disappeared in: https://github.com/dlang/dmd/pull/3020 The misleading "overload" diagnostic was introduced in: https://github.com/dlang/dmd/pull/13544

--