[Issue 22241] New: Compiler fails to match a more specialized overload

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed Aug 25 19:48:05 UTC 2021


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 at puremagic.com
          Reporter: maxsamukha at 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.

--


More information about the Digitalmars-d-bugs mailing list