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

S2259: Support NotNullWhenAttribute #6128

Closed
pavel-mikula-sonarsource opened this issue Sep 22, 2022 · 0 comments · Fixed by #6137
Closed

S2259: Support NotNullWhenAttribute #6128

pavel-mikula-sonarsource opened this issue Sep 22, 2022 · 0 comments · Fixed by #6137
Assignees
Labels
Area: C# C# rules related issues. Area: CFG/SE CFG and SE related issues. Area: VB.NET VB.NET rules related issues.
Milestone

Comments

@pavel-mikula-sonarsource
Copy link
Contributor

pavel-mikula-sonarsource commented Sep 22, 2022

We should learn states from parameters decorated with [NotNullWhen] attributes.

if(int.TryParse(value, out var i))
{
    value.ToString(); // Definitely not null
}
else
{
    value.ToString(); // Noncompliant, could be null
}
@pavel-mikula-sonarsource pavel-mikula-sonarsource added Type: Improvement Area: CFG/SE CFG and SE related issues. Area: VB.NET VB.NET rules related issues. Area: C# C# rules related issues. labels Sep 22, 2022
@pavel-mikula-sonarsource pavel-mikula-sonarsource added this to the 8.46 milestone Sep 22, 2022
@pavel-mikula-sonarsource pavel-mikula-sonarsource changed the title S2259: Support DoesNotReturnIfAttribute S2259: Support DoesNotReturnIfAttribute and NotNullWhenAttribute Sep 29, 2022
@pavel-mikula-sonarsource pavel-mikula-sonarsource changed the title S2259: Support DoesNotReturnIfAttribute and NotNullWhenAttribute S2259: Support NotNullWhenAttribute Oct 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: C# C# rules related issues. Area: CFG/SE CFG and SE related issues. Area: VB.NET VB.NET rules related issues.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants