www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 24437] New: Optional arguments changing overload preference

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

          Issue ID: 24437
           Summary: Optional arguments changing overload preference when
                    compared to a varatic function
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: crazymonkyyy gmail.com

```d
import std;
auto notfoo(T)(T[] args...){
        "wrong function 1".writeln;
}
auto notfoo(T,S)(T[S] args){
        "right function 1".writeln;
}
auto notfoo2(T)(T[] args...){
        "wrong function 2".writeln;
}
auto notfoo2(T,S)(T[S] args,int i=1000){
        "right function 2".writeln;
}
void main(){
        [1:'a',2:'b',3:'c'].notfoo;
        "---".writeln;
        [1:'a',2:'b',3:'c'].notfoo2;
}
```

right function 1
---
wrong function 2


https://dlang.org/spec/function.html#function-overloading
 7. A function with a variadic argument is considered less specialized than a
function without.
--
Mar 14