Bug 23897 – Bad diagnostic "none of the overloads of template" for lamdba

Status
RESOLVED
Resolution
FIXED
Severity
regression
Priority
P4
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2023-05-06T16:11:04Z
Last change time
2023-05-08T15:16:40Z
Keywords
diagnostic
Assigned to
No Owner
Creator
Vladimir Panteleev
See also
https://issues.dlang.org/show_bug.cgi?id=20268

Comments

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
Comment #1 by nick — 2023-05-06T17:40:23Z
> The misleading "overload" diagnostic was introduced in: https://github.com/dlang/dmd/pull/13544 I'm working on a pull to fix that now.
Comment #2 by dlang-bot — 2023-05-06T18:01:02Z
@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