Skip to content

Ambiguous method call for Task of nullable types #725

Open
@FNERNST

Description

@FNERNST

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugReported problem with NSubstitute behaviour

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions