Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[Feature]: Suppress nullable warning #5200

Copy link
Copy link

Description

@splendid25
Issue body actions

Problem Statement

Hi,

Assert.That().IsNotNull() don't suppress nullable warnings for some code after the Assert.
The following code gives a warning CS8629 "Nullable value type may be null." when the Id is guaranteed to be not null after the Assert.

Proposed Solution

[Test]
[Arguments(1)]
public async Task CheckNull(int? id)
{
    var value = new
    {
        Id = id
    };

    await Assert.That(value.Id)
                .IsNotNull();

    await Assert.That(value.Id.Value)
                .EqualTo(0);
}

Alternatives Considered

For example with an extra if ... is not null, the compiler can suppress the warning :

[Test]
[Arguments(1)]
public async Task CheckNull(int? id)
{
    var value = new
    {
        Id = id
    };

    await Assert.That(value.Id)
                .IsNotNull();

    if (value.Id is not null)
    {
        await Assert.That(value.Id.Value)
                    .EqualTo(0);
    }
}

Feature Category

Other

How important is this feature to you?

Nice to have - would improve my experience

Additional Context

No response

Contribution

  • I'm willing to submit a pull request for this feature
Reactions are currently unavailable

Metadata

Metadata

Labels

enhancementNew feature or requestNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

Morty Proxy This is a proxified and sanitized view of the page, visit original site.