www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 20586] New: Ambiguous overload set with default parameter

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

          Issue ID: 20586
           Summary: Ambiguous overload set with default parameter gives
                    confusing error message
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Keywords: diagnostic
          Severity: minor
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: pro.mathias.lang gmail.com

The following code:
```
void main () nothrow
{
    foo("hello");
}

void foo (string)  system nothrow {}
void foo (string)  safe { }
```

Results in the following error message:
```
test.d(3): Error: test.foo called with argument types (string) matches both:
test.d(6):     test.foo(string)
and:
test.d(7):     test.foo(string)
```

But when changing the definition of `foo` to:
```
void foo (string, float f = 42)  system nothrow {}
void foo (string, int a = 42)  safe { }
```

We get:
```
test.d(6): Error: function nope.foo is not nothrow
test.d(1): Error: nothrow function D main may throw
```

Which, if a user expect overloading to work with different attributes, is
confusing.

--
Feb 19