Skip to content

[Bug]: Assert.That(() => GetNameAsync()) still warns CS8619 (the lambda case of #3422) #7795

Done

Description

@JohnVerheij

Bug report checklist

  • I've searched existing issues to ensure this isn't a duplicate
  • I've read the documentation and this isn't expected behavior
  • I'm using the latest version of TUnit

Description

Passing a lambda that returns a Task<T> of a non-nullable reference type to Assert.That without async gives CS8619, because the overload takes Func<Task<TValue?>> and Task<string> is not Task<string?>. With warnings as errors the build fails.

This is the second case of #3422. #3429 fixed the Assert.That(value) warning from that issue and added Issue3422Tests for both cases, but its lambda test still warns on main:

Issue3422Tests.cs(24,33): warning CS8619: Nullability of reference types in value of type 'Task<object>' doesn't match target type 'Task<object?>'.

TUnit.Assertions.Tests does not treat warnings as errors, so that test passes anyway. #3582 fixed the same warning for Assert.That(Task<T>), the task itself; the lambda form still has it. An async () => await GetNameAsync() lambda does not warn.

Expected Behavior

No warning: the lambda's task result is non-nullable, which the assertion can take as it is.

Actual Behavior

warning CS8619 on the Assert.That(() => ...) line (an error with warnings as errors).

Steps to Reproduce

private static Task<string> GetNameAsync() => Task.FromResult("Alice");

[Test]
public async Task Name()
{
    await Assert.That(() => GetNameAsync()).IsEqualTo("Alice");   // CS8619
}

TUnit Version

1.85.7

.NET Version

net10.0

Operating System

Windows

IDE / Test Runner

dotnet CLI (dotnet test / dotnet run)

Error Output / Stack Trace

warning CS8619: Nullability of reference types in value of type 'Task<string>' doesn't match target type 'Task<string?>'.

Additional Context

I have a small fix along the lines of #3582, with tests, and will open a PR.

IDE-Specific Issue?

  • I've confirmed this issue occurs when running via dotnet test or dotnet run, not just in my IDE

Activity

  1. added
    bug
    on Nov 16, 2026
  2. added
    P2
    on Nov 16, 2026
  3. added a commit that references this issue on Nov 29, 2026
    3610e5b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions