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

Suppress nullability warnings after Is.Not.Null constraint #157

Closed
Dreamescaper opened this issue Oct 11, 2019 · 3 comments · Fixed by #325
Closed

Suppress nullability warnings after Is.Not.Null constraint #157

Dreamescaper opened this issue Oct 11, 2019 · 3 comments · Fixed by #325

Comments

@Dreamescaper
Copy link
Member

As discussed here nunit/nunit#3376 (comment), it would be great to suppress nullability warnings after Is.Not.Null asserts, e.g.

string? str = GetNullable();
Assert.That(str, Is.Not.Null);
Assert.That(str.Length, Is.Not.Zero);  // <----- should be no warning here

Unfortunately, we cannot impact roslyn's nullability analysis, only suppress analyzers (see dotnet/roslyn#32042 (comment)), which means that at least very basic logic should be re-invented.

Cases that I think should be covered:
Assert.That(obj?.PropA?.PropB, Is.Not.Null)
Assert.That(obj, Is.Not.Null & Is.Not.Empty)
Assert.That(obj, Is.Not.Null.And.Not.Empty)

Assert.Multiple(() =>
{
	string? str = GetNullable();
	Assert.That(str, Is.Not.Null);
	Assert.That(str.Length, Is.Not.Zero);  // <----- warning should remain here
});
@mikkelbu
Copy link
Member

I can definitely see the benefit of this, but also the complexity if we want to handle more than the most basic cases, as we would have to implement the same flow analysis as in the compiler.

So the easiest is probably to start with the most basic example and then build upon this.

@Dreamescaper
Copy link
Member Author

Dreamescaper commented Nov 3, 2019

The only concern is - doing that would probably require to drop VS2017 support (or provide separate package for VS2017).
I don't know any way to reference Roslyn 3.0 package and maintain compatibility with VS2017.

@manfred-brands
Copy link
Member

I'm looking into the use of a DiagnosticsSuppressor.

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.

3 participants