www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 22241] New: Compiler fails to match a more specialized overload

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

          Issue ID: 22241
           Summary: Compiler fails to match a more specialized overload
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Keywords: rejects-valid, spec
          Severity: major
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: maxsamukha gmail.com

In the following, the specialized parameter (int a) takes over the general one
(T a) as expected:

int foo()(int a)
{
    return 1;
}

int foo(T)(T a)
{
    return 2;
}

void main()
{
    int x;
    assert(foo(x) == 1); // ok
    assert(foo("a") == 2); // ok
}


But, if another general parameter is added, the "matches both" error occurs:

int foo(T)(T t, int a)
{
    return 1;
}

int foo(T, U)(T t, U a)
{
    return 2;
}

void main()
{
    int x;
    assert(foo(0, x) == 1);
    assert(foo(0, "a") == 2);
}

onlineapp.d(14): Error: `onlineapp.foo` called with argument types `(int, int)`
matches both...

Both should be either rejected or accepted.

--
Aug 25 2021