I was surprised to find out that the return type on a method can create an overload ambiguity when passing the method in to another method. Since the return type is not part of the signature, it's hard to see how changing the return value could create ambiguity where it had not previously existed. Yet this seems to be the case for void and Task. Consider the following:
class Signature
{
static public void Overload(Func<Task> countasync)
{
}
static public void Overload(Action count)
{
}
}
void Decrement() { }
Task IncrementAsync() { return Task.CompletedTask; }
void TestSig()
{
Signature.Overload(this.IncrementAsync); // no compile time error
Signature.Overload(this.Decrement); // compile time error: this call is ambiguous
}
Is there a way to define the Overload argument types so that the second call is not ambiguous, while still allowing the first call?