Bug 23424 – improve error when template instantiation doesn't match any overload
Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2022-10-17T17:06:19Z
Last change time
2022-10-31T00:46:52Z
Keywords
diagnostic
Assigned to
No Owner
Creator
Steven Schveighoffer
Comments
Comment #0 by schveiguy — 2022-10-17T17:06:19Z
If I create a template that accepts a type, and try to instantiate it with something other than a type, it fails with a clear message:
```d
template T(X) { int v; }
void main() {
T!(1).v = 5;
}
```
Error: template instance `T!1` does not match template declaration `T(X)`
However, if I create just one overload, it no longer helps me with the clear message:
```d
template T(X) { int v; }
template T() { int v; }
void main() {
T!(1).v = 5;
}
```
Error: template `onlineapp.T` does not match any template declaration
It tells me the template FQN, but the "does not match any template declaration" is puzzling -- yes, it doesn't match any overloaded declaration, but it seems to suggest there is no declaration.
Comparing to a failure to match a function template:
```d
void T(X)() { int v; }
void T()() { int v; }
void main() {
T!(1)();
}
```
Error: none of the overloads of template `onlineapp.T` are callable using argument types `!(1)()`
Candidates are: `T(X)()`
`T()()`
This is very clear and informative. It also identifies possible things that it tries, just like the non-overloaded template example.
A similar approach should be done for non-function templates.
Comment #1 by dlang-bot — 2022-10-30T18:20:02Z
@ntrel created dlang/dmd pull request #14603 "Issue 23424 - improve error when template instantiation doesn't match…" mentioning this issue:
- Issue 23424 - improve error when template instantiation doesn't match any overload
https://github.com/dlang/dmd/pull/14603
Comment #2 by dlang-bot — 2022-10-31T00:46:52Z
dlang/dmd pull request #14603 "Fix Issue 23424 - improve error when template instantiation doesn't match an overload" was merged into master:
- c0243596948a75e709c96afbbf9d48919f884bb4 by Nick Treleaven:
Fix Issue 23424 - improve error when template instantiation doesn't match any overload
https://github.com/dlang/dmd/pull/14603