Comment #0 by dlang-bugzilla — 2023-05-06T16:11:04Z
/////////// 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
@ntrel created dlang/dmd pull request #15194 "Fix 'overloads' error when there are no overloads" mentioning this issue:
- Fix 'overloads' error when there are no overloads
Part of Issue 23897 - Bad diagnostic "none of the overloads of template"
for lamdba.
https://github.com/dlang/dmd/pull/15194
Comment #3 by nick — 2023-05-06T18:28:53Z
> Especially the last line is very useful, and is missing entirely from new compilers.
With git master, I do get the parameters:
Candidate is: `__lambda1(__T1, __T2)(a, b)`
Comment #4 by dlang-bugzilla — 2023-05-06T20:29:22Z
(In reply to Nick Treleaven from comment #3)
> > Especially the last line is very useful, and is missing entirely from new compilers.
>
> With git master, I do get the parameters:
>
> Candidate is: `__lambda1(__T1, __T2)(a, b)`
Indeed, it was fixed in https://github.com/dlang/dmd/pull/15113 (so that half is duplicate of issue 20268). Thanks!
Comment #5 by dlang-bot — 2023-05-08T11:42:04Z
dlang/dmd pull request #15194 "Fix 'overloads' error when there are no overloads" was merged into master:
- 2cf91b9484a1b639529d67e2a49e2ca07e2b664a by Nick Treleaven:
Fix 'overloads' error when there are no overloads
Part of Issue 23897 - Bad diagnostic "none of the overloads of template"
for lamdba.
https://github.com/dlang/dmd/pull/15194