Bug 21362 - Ambiguous call to overloaded method with default arguments should emit a warning or be a compiler error
Summary: Ambiguous call to overloaded method with default arguments should emit a warn...
Alias: None
Product: Compilers
Classification: Mono
Component: C# ()
Version: 3.4.0
Hardware: PC Linux
: --- normal
Target Milestone: ---
Assignee: Marek Safar
Depends on:
Reported: 2014-07-16 06:55 UTC by delcypher
Modified: 2014-07-16 12:03 UTC (History)
2 users (show)

Is this bug a regression?: ---
Last known good build:

Simple program illustrating ambiguous call (504 bytes, text/x-csharp)
2014-07-16 06:55 UTC, delcypher

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description delcypher 2014-07-16 06:55:57 UTC
Created attachment 7383 [details]
Simple program illustrating ambiguous call

1. Compile attached program


The application should not compile (or at the very least a warning should be emitted) due to the ambiguous method call

What happens:

Compilation succeeds without error and no warnings!

More details:

I also tested in Microsoft Visual Studio 2012 and it doesn't emit a warning or fail to compile either which surprised me.

The basic essence of the issue is calling a method like this...

foo(5, true);

with the following methods defined

public static void foo(int a, bool c=true)
public static void foo(int a, bool b, bool c=true)

is ambiguous to the developer (I don't know if it is ambiguous in the C# language specification).
Comment 1 Marek Safar 2014-07-16 07:49:38 UTC
The call is not ambiguous according to C# overloading resolution rules specification
Comment 2 delcypher 2014-07-16 09:02:51 UTC
> The call is not ambiguous according to C# overloading resolution rules

I just had a quick look at the spec and I assume you're referring to 

From Better function member

Otherwise if all parameters of MP have a corresponding argument whereas default arguments need to be substituted for at least one optional parameter in MQ then MP is better than MQ.

Be that as it may I think emitting a warning would be useful because most developers are not going to be experts in the overloading rules in the language specification. A warning could easily be silenced by rewriting the call as



foo(5, true, true)

depending on which method the developer actually wants to call.
Comment 3 Marek Safar 2014-07-16 12:01:21 UTC
That's not going to happen. C# developers should know rules of the language and if the they are not sure then check the spec. Issuing warning would break compatibility with csc and still not address the issue as same rules are used in other contexts like type inference, etc.
Comment 4 delcypher 2014-07-16 12:03:10 UTC
Okay it's a WONTFIX then.