[Issue 20713] New: Improve Template Deduction Error Message Given Template Parameter Default Values

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Mar 31 15:24:52 UTC 2020


https://issues.dlang.org/show_bug.cgi?id=20713

          Issue ID: 20713
           Summary: Improve Template Deduction Error Message Given
                    Template Parameter Default Values
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: john.michael.hall at gmail.com

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.

--


More information about the Digitalmars-d-bugs mailing list