NSubstitute
NSubstitute copied to clipboard
Ambiguous method call for Task of nullable types
Describe the bug When using the Returns extension method with a Task that may contain a nullable value, the method is ambiguous. The same happens for non primitive nullable types. See the example below which results in a compilation error.
To Reproduce
public interface ITest
{
Task<int?> TestAsync();
}
var test = Substitute.For<ITest>();
test.TestAsync().Returns(Task.FromResult(1));
Expected behaviour The correct Returns method is called.
Environment:
- NSubstitute version: 5.0.0
- NSubstitute.Analyzers version: CSharp 1.0.16
- Platform: .NET Core 7 on macOS
I can confirm this issue:
The issue is that Task.FromResult(1); will create a Task<int> and not a Task<int?>