-
-
Notifications
You must be signed in to change notification settings - Fork 118
Closed
Description
Description
In a similar vein to #3422, I'm getting warnings in the following situations with asynchronous operations:
[Test]
[Arguments(null, null)]
[Arguments("test", "test")]
[Arguments(123, 123)]
public async Task Assert_That_With_Async_Object_Nullable_Parameters_Should_Not_Cause_Warnings(object? value, object? expected)
{
// This should not produce CS8620 or CS8619 warnings, but triggers CS8620 warning
await Assert.That(Task.FromResult(value)).IsEqualTo(expected);
}
[Test]
[Arguments("test", "test")]
[Arguments(123, 123)]
public async Task Assert_That_With_Async_Object_Parameter_And_Nullable_Expectation_Should_Not_Cause_Warnings(object value, object? expected)
{
// This should not produce CS8620 or CS8619 warnings, but triggers CS8620 warning
await Assert.That(Task.FromResult(value)).IsEqualTo(expected);
}
[Test]
[Arguments("test", "test")]
[Arguments(123, 123)]
public async Task Assert_That_With_Async_Object_Parameters_Should_Not_Cause_Warnings(object value, object expected)
{
// This should not produce CS8620 or CS8619 warnings, but triggers CS8619 warning
await Assert.That(Task.FromResult(value)).IsEqualTo(expected);
}Reproduction
To reproduce the issue, you can edit the TUnit.Assertions.Tests/Bugs/Issue3422Tests.cs file (click for diff)
File: TUnit.Assertions.Tests/Bugs/Issue3422Tests.cs
namespace TUnit.Assertions.Tests.Bugs;
/// <summary>
/// Tests for issue #3422: CS8620 and CS8619 warnings with object? parameters
/// https://github.com/thomhurst/TUnit/issues/3422
/// </summary>
public class Issue3422Tests
{
[Test]
[Arguments(null, null)]
[Arguments("test", "test")]
[Arguments(123, 123)]
public async Task Assert_That_With_Object_Nullable_Parameters_Should_Not_Cause_Warnings(object? value, object? expected)
{
// This should not produce CS8620 or CS8619 warnings
await Assert.That(value).IsEqualTo(expected);
}
+ [Test]
+ [Arguments(null, null)]
+ [Arguments("test", "test")]
+ [Arguments(123, 123)]
+ public async Task Assert_That_With_Async_Object_Nullable_Parameters_Should_Not_Cause_Warnings(object? value, object? expected)
+ {
+ // This should not produce CS8620 or CS8619 warnings
+ await Assert.That(Task.FromResult(value)).IsEqualTo(expected);
+ }
+
+ [Test]
+ [Arguments("test", "test")]
+ [Arguments(123, 123)]
+ public async Task Assert_That_With_Async_Object_Parameters_And_Mix_Of_Nullability_Should_Not_Cause_Warnings(object value, object? expected)
+ {
+ // This should not produce CS8620 or CS8619 warnings
+ await Assert.That(Task.FromResult(value)).IsEqualTo(expected);
+ }
+
+ [Test]
+ [Arguments("test", "test")]
+ [Arguments(123, 123)]
+ public async Task Assert_That_With_Async_Object_Parameters_Should_Not_Cause_Warnings(object value, object expected)
+ {
+ // This should not produce CS8620 or CS8619 warnings
+ await Assert.That(Task.FromResult(value)).IsEqualTo(expected);
+ }and run:
dotnet test --project TUnit.Assertions.Tests --framework net9.0 --treenode-filter '/*/*/Issue3422Tests/*' --output Detailedwhich outputs:
./TUnit.Assertions.Tests/Bugs/Issue3422Tests.cs(35,27): warning CS8620: Argument of type 'Task<object>' cannot be used for parameter 'task' of type 'Task<object?>' in 'TaskAssertion<object> Assert.That<object>(Task<object?> task, string? expression = null)' due to differences in the nullability of reference types.
./TUnit.Assertions.Tests/Bugs/Issue3422Tests.cs(44,27): warning CS8620: Argument of type 'Task<object>' cannot be used for parameter 'task' of type 'Task<object?>' in 'TaskAssertion<object> Assert.That<object>(Task<object?> task, string? expression = null)' due to differences in the nullability of reference types.
./TUnit.Assertions.Tests/Bugs/Issue3422Tests.cs(52,33): warning CS8619: Nullability of reference types in value of type 'Task<object>' doesn't match target type 'Task<object?>'.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels