-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Champion "Improved overload candidates" (15.7) #98
Comments
We should also look whether we should do something similar for the lambda conversion (say the conversion doesn't exist when the return type is wrong). See dotnet/roslyn#8942 |
@gafter Per LDM today, since it not technically a change to overload resolution, but rather the steps before (weeding out candidates) and after (removing any redundant logic to final verification). Should we rename the issue? |
@jcouv I think keeping the name stable helps us recall what we were talking about. But I don't feel strongly about it one way or another. Do you have a suggested name? "Better method candidate selection"? |
This likely deserves a whole other discussion, but: overload resolution based on generic constraints would be so wonderful. |
@scalablecory This would have the side-effect of permitting overload resolution based on generic constraints. You would still have to ensure that the method signatures are different enough that they would not clash in IL. FYI, I'm implementing this now. |
- Refine candidate set based on static/instance receiver, or static context - Refine candidate methods whose type parameter constraints are violated. - For a method group conversion, remove methods with the wrong return type or ref mode. Implements dotnet/csharplang#98 See also dotnet#24675 for a proposal to improve the quality of diagnostics for the method group conversion. This change occasionally exposes this opportunity for diagnostic improvement (search for references to dotnet#24675 in the source to find examples).
…4756) - Implement improved overload candidates, aka "Bestest Betternes". - Refine candidate set based on static/instance receiver, or static context - Refine candidate methods whose type parameter constraints are violated. - For a method group conversion, remove methods with the wrong return type or ref mode. - Implement improved diagnostics for some cases of method group conversion failure Implements dotnet/csharplang#98 Fixes #24675
the "smallish feature" tag on this blows my mind. there should be a sign next to anything related to overload resolution that reads "KEEP OUT". |
Is there any plan to change the behavior describe here: dotnet/roslyn#250 (comment) Resolving the overload with the Things get weirder when a third overload with As soon as a void Test()
{
Method(char.MaxValue);
Method(byte.MaxValue);
Method(short.MaxValue);
Method(int.MaxValue);
Method(long.MaxValue);
Method(float.MaxValue);
}
void Method(float value) { } // all calls resolved to that overload
void Method(double value) { }
//void Method(decimal value) { } |
Changing the behavior where the code currently compiles would be a breaking change and could adversely affect existing programs. IIRC all of the improvements above were to eliminate overload candidates in situations where the code would fail to compile due to an ambiguity but where some of the candidates would not be invocable. |
@Kryptos-FR No, there are no such plans. |
@HaloFour It could be an opt-in compilation switch to enforce "stricter" rules regarding overload resolution. In that mode the above examples would fail to compile with a meaningful error message but without that switch (default behavior) it will compile as usual. |
That would create a dialect in the language which the team would be very unlikely to consider. |
@richard-fine It has been shipped in C# 7.3, as you can see here, which comes with Visual Studio 15.7. |
The language spec is stuck at version 6 while we work with ECMA to plan how we're going to evolve it going forward. Having said that, you can find specs of varying degrees of precision for recently shipped features |
CS0121: The call is ambiguous between the following methods or properties: 'Device.InvokeOnMainThreadAsync(Action)' and 'Device.InvokeOnMainThreadAsync(Func<Task>)' dotnet/roslyn#14885 dotnet/csharplang#98
…6718) * [Core] Use local functions * [Core] Extract DeviceUnitTests * [Core] Ensure actually called from main thread * [Core] Add InvokeOnMainThread tests WithAsyncTask is expected to fail. * [Core] Rename local wrapper functions * [Core] Avoid ambiguous call CS0121: The call is ambiguous between the following methods or properties: 'Device.InvokeOnMainThreadAsync(Action)' and 'Device.InvokeOnMainThreadAsync(Func<Task>)' dotnet/roslyn#14885 dotnet/csharplang#98
Any news about that? |
This has been implemented since C# 7.3. |
@Nintynuts dotnet/roslyn#26077 was closed because it doesn't repro as of C# 7.3. |
@jcouv I tried to build an example to demonstrate and couldn't reproduce the issue. It turned out that a nuget reference to |
Standard spec in progress at dotnet/csharpstandard#263 |
see dotnet/roslyn#250
The overload resolution rules have been updated in nearly every C# language update to improve the experience for programmers, making ambiguous invocations select the "obvious" choice. This has to be done carefully to preserve backward compatibility, but since we are usually resolving what would otherwise be error cases, these enhancements usually work out nicely.
There are three cases we might consider improving in C# 7:
this
instance receiver cannot be used, includes the body of members where nothis
is defined, such as static members, as well as places wherethis
cannot be used, such as field initializers and constructor-initializers.There are probably additional improvements we could consider.
The text was updated successfully, but these errors were encountered: