Skip to content
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

Ambiguous method call for Task of nullable types #725

Open
FNERNST opened this issue Aug 17, 2023 · 1 comment
Open

Ambiguous method call for Task of nullable types #725

FNERNST opened this issue Aug 17, 2023 · 1 comment
Assignees
Labels
bug Reported problem with NSubstitute behaviour

Comments

@FNERNST
Copy link

FNERNST commented Aug 17, 2023

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
@FNERNST FNERNST changed the title Ambiguous method call with Task of nullable types Ambiguous method call for Task of nullable types Aug 17, 2023
@304NotModified 304NotModified added the bug Reported problem with NSubstitute behaviour label Apr 29, 2024
@304NotModified
Copy link
Contributor

304NotModified commented Apr 30, 2024

I can confirm this issue:

image

The issue is that Task.FromResult(1); will create a Task<int> and not a Task<int?>

@304NotModified 304NotModified self-assigned this Apr 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Reported problem with NSubstitute behaviour
Projects
None yet
Development

No branches or pull requests

2 participants