Comment #0 by john.michael.hall — 2020-03-31T15:24:52Z
The fix for Issue 10438 means improved error messages for template constraints for functions. However, the fix does not resolve the issue for template parameter default values.
Resolving Issue 10438 meant that
void foo(T, U)(T t, U u) if (is(T == int) && is(U == int)) {}
void main()
{
foo("hello", 4);
}
will produce the error
onlineapp.d(5): Error: template onlineapp.foo cannot deduce function from argument types !()(string, int), candidates are:
onlineapp.d(1): foo(T, U)(T t, U u)
with T = string,
U = int
must satisfy the following constraint:
is(T == int)
However, if you modify the above code to
template foo(int x = 0) {
void foo(T, U)(T t, U u)
if (is(T == int) && is(U == int)) {}
}
void main()
{
foo("hello", 4);
}
Then the error message is just
onlineapp.d(12): Error: template onlineapp.foo cannot deduce function from argument types !()(string, int), candidates are:
onlineapp.d(5): foo(int x = 0)
Note that this is not a problem for
void main()
{
foo!1("hello", 4);
}
which will produce the error
onlineapp.d(8): Error: template onlineapp.foo!1.foo cannot deduce function from argument types !()(string, int), candidates are:
onlineapp.d(2): foo(T, U)(T t, U u)
with T = string,
U = int
must satisfy the following constraint:
is(T == int)
This indicates that the problem is with template deduction error messages with the template parameter default values.
Comment #1 by dlang-bot — 2024-09-04T16:54:59Z
@ntrel created dlang/dmd pull request #16827 "Show nested template function signature in candidate message" mentioning this issue:
- Show nested template function signature in candidate message
Part of Bugzilla 20713 - Improve Template Deduction Error Message Given Template Parameter Default Values
https://github.com/dlang/dmd/pull/16827
Comment #2 by dlang-bot — 2024-09-05T00:33:40Z
dlang/dmd pull request #16827 "Show nested template function signature in candidate message" was merged into master:
- 0f23b9c3c0677c581e7ba277d6edcae5b8c6444f by Nick Treleaven:
Show nested template function signature in candidate message
Part of Bugzilla 20713 - Improve Template Deduction Error Message Given Template Parameter Default Values
https://github.com/dlang/dmd/pull/16827
Comment #3 by robert.schadek — 2024-12-13T19:08:00Z