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

DiagnosticSuppressor doesn't suppress values passed as arguments #535

Closed
manfred-brands opened this issue Apr 26, 2023 · 0 comments · Fixed by #536
Closed

DiagnosticSuppressor doesn't suppress values passed as arguments #535

manfred-brands opened this issue Apr 26, 2023 · 0 comments · Fixed by #536
Assignees

Comments

@manfred-brands
Copy link
Member

If a nullable variable is asserted to be not null and then passed to a method that expects a non-nullable instance, the errors are not suppressed, even if the variable is assigned to a local variable first.

[Test]
public void TestPassDirectly()
{
    string? possibleNull = GetNext();
    Assert.That(possibleNull, Is.Not.Null);
    AssertEmpty((string)possibleNull);
}

[Test]
public void TestPassViaLocal()
{
    string? possibleNull = GetNext();
    Assert.That(possibleNull, Is.Not.Null);
    string s = (string)possibleNull;
    AssertEmpty(s);
}

private static string? GetNext() => string.Empty;

private static void AssertEmpty(string s) => Assert.That(s, Is.EqualTo(string.Empty));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants