[Issue 23424] New: template with overloads not clear why it doesn't match
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Mon Oct 17 17:06:19 UTC 2022
https://issues.dlang.org/show_bug.cgi?id=23424
Issue ID: 23424
Summary: template with overloads not clear why it doesn't match
Product: D
Version: D2
Hardware: All
OS: All
Status: NEW
Keywords: diagnostic
Severity: enhancement
Priority: P1
Component: dmd
Assignee: nobody at puremagic.com
Reporter: schveiguy at gmail.com
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.
--
More information about the Digitalmars-d-bugs
mailing list