www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 21457] New: std.functional.partial ignores function overloads

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

          Issue ID: 21457
           Summary: std.functional.partial ignores function overloads
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P1
         Component: phobos
          Assignee: nobody puremagic.com
          Reporter: snarwin+bugzilla gmail.com

As of DMD 2.094.0, the following program fails to compile:

---
import std.functional;

void fun(int x, string s) {}
void fun(int x, int y) {}

alias pfun = partial!(fun, 0);

void main()
{
    pfun("hello"); // ok
    pfun(123); // error
}
---

The compiler's output is:

---
bug.d(11): Error: function std.functional.partial!(fun, 0).partial(string
_param_0) is not callable using argument types (int)
bug.d(11):        cannot pass argument 123 of type int to parameter string
_param_0
---

The cause is that partial!(fun, 0)(123) is attempting to call the first
overload of `fun`, when it should instead be calling the second overload.

--
Dec 06 2020