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

Fix S112 FN: When using null-coalesce operator #7910

Closed
nalka0 opened this issue Aug 28, 2023 · 2 comments · Fixed by #7911
Closed

Fix S112 FN: When using null-coalesce operator #7910

nalka0 opened this issue Aug 28, 2023 · 2 comments · Fixed by #7911
Assignees
Labels
Area: C# C# rules related issues. Type: False Negative Rule is NOT triggered when it should be.
Projects
Milestone

Comments

@nalka0
Copy link
Contributor

nalka0 commented Aug 28, 2023

Description

S112 isn't raised when throw new Exception(); is used with null-coalesce operator

Repro steps

var test = "" ?? throw new Exception(); // Doesn't raise S112
throw new Exception(); // Raises S112

Expected behavior

S112 is raised on both lines

Actual behavior

S112 is raised only on the second line

Known workarounds

Not using null-coalesce operator

Related information

  • SonarLint for Visual Studio 2022 Version 7.2.0.76209
  • Visual Studio Professional 2022 Version 17.6.4
  • .Net Framework 4.7.2 / .Net 6.0
  • Windows 11
@pavel-mikula-sonarsource
Copy link
Contributor

Hi @nalka0,

Thank you for reporting this case, I confirm it as FN.

@pavel-mikula-sonarsource pavel-mikula-sonarsource added Type: False Negative Rule is NOT triggered when it should be. Area: C# C# rules related issues. labels Aug 29, 2023
@pavel-mikula-sonarsource pavel-mikula-sonarsource added this to the 9.9 milestone Aug 29, 2023
@github-actions github-actions bot added this to To do in Best Kanban Aug 29, 2023
@pavel-mikula-sonarsource pavel-mikula-sonarsource changed the title Fix S112 FN when using null-coalesce operator Fix S112 FN: When using null-coalesce operator Aug 29, 2023
@pavel-mikula-sonarsource pavel-mikula-sonarsource moved this from To do to In progress in Best Kanban Aug 29, 2023
@pavel-mikula-sonarsource
Copy link
Contributor

Other scenarios:
Lambda

_ => throw new Exception()

and arrow methods

public void Go() => throw new Exception();

@github-actions github-actions bot moved this from In progress to Review in progress in Best Kanban Aug 29, 2023
@github-actions github-actions bot moved this from Review in progress to Review approved in Best Kanban Aug 29, 2023
Best Kanban automation moved this from Review approved to Validate Peach Aug 29, 2023
@pavel-mikula-sonarsource pavel-mikula-sonarsource moved this from Validate Peach to Done in Best Kanban Sep 1, 2023
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. Type: False Negative Rule is NOT triggered when it should be.
Projects
Best Kanban
  
Done
Development

Successfully merging a pull request may close this issue.

3 participants