-
Notifications
You must be signed in to change notification settings - Fork 4.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
Overload resolution for method groups and Action/Func<Task> overloads #26077
Comments
tagging @agocke . IT does seem weird to have ambiguity, given that one of the overloads expect |
@CyrusNajmabadi Yes, Im not getting the ambiguity part of the error message |
Doesn't look like this has anything to do with local functions: using System.Threading.Tasks;
public class C
{
public void M()
{
Task.Run(M2);
}
void M2()
{
}
} Output: Plain old overload resolution. |
cc @gafter |
@agocke Thanks, so is this considered as a bug or more a (known) design issue? (in the overload resolution space) |
This appears to be a bug, since I don't think there's a conversion from |
Doesn't repro on master. worth to add a test maybe |
It looks like this was part of the "bestest betterness" feature implemented for C# 7.3 (which is why it does not repro in master). See https://github.com/dotnet/csharplang/blob/master/proposals/csharp-7.3/improved-overload-candidates.md for the specification, specifically number (3), which addresses this scenario. |
Version Used:
Latest
Steps to Reproduce:
See:
https://sharplab.io/#v2:CYLg1APgAgDABFAjAbgLAChYMQVjZgZgQCY4BhODAbwwEgM5GEAWOAGQHsBjAQwBsoOAC4BLDgDsAFElI8uoiQEoGTGuiYa4ANx4AnOLwAOQgK66ApnAC8cAERkexs+eC38mplFZc+HAM7OksrqHnBqoZo6+r68fNYGjqYW7hFMKqlwcgpSiikeAL7pmkUaAPSlUABsAHQASiZSPv7OuXDlcA1cHAC23ebiQnBCABYifkWFIYxFXtjEACLmfOYA5jxC5tKIsvJi4sEa4aFRCU4W8faJzq55mjIGvgHnNkHWAHwlqp8eJzH88UYkuZbhFvposnsgiCmPlodMpncavVGo8Wrd8pQERh8kA
Expected Behavior:
I would expect that the two examples are identical and both should compile
Actual Behavior:
error CS0121: The call is ambiguous between the following methods or properties: 'Task.Run(Action)' and 'Task.Run(Func<Task>)'
What I am not getting is that the compiler says that is has to choose between
Task.Run(Action)
andTask.Run(Func<Task>)
but my closure clearly has the same signature as an Action right? (no param, no return)Edit: the fun thing is that Visual Studio (analyzer + fix) hints for using a local function, which results in a compiler error @kuhlenh
The text was updated successfully, but these errors were encountered: