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 S2683 FP: Nullable<bool> ?? false #2337

Closed
YairHalberstadt opened this issue Mar 12, 2019 · 1 comment
Closed

Fix S2683 FP: Nullable<bool> ?? false #2337

YairHalberstadt opened this issue Mar 12, 2019 · 1 comment
Labels
Area: C# C# rules related issues. Type: False Positive Rule IS triggered when it shouldn't be.
Milestone

Comments

@YairHalberstadt
Copy link

Repro steps

Install SonarAnalyzer.CSharp and compile the following code:

using System;

class Program
{
	static void Main(string[] args)
	{
		var obj = args.Length > 0 ? new Program() : null;

		if (obj?.Cond ?? false)
		{
			Console.WriteLine("Foo");
			Console.WriteLine("Bar");
		}
	}

	private bool Cond = new Random().Next() % 2 == 1;
}

Expected behavior

No warning

Actual behavior

Warning S2583 on line 9:

Change this condition so that it does not always evaluate to 'false'; some subsequent code is never executed.

Related information

#152 and #162 are similar, but have been fixed

@Evangelink Evangelink added Area: Rules Type: False Positive Rule IS triggered when it shouldn't be. Area: C# C# rules related issues. labels Mar 27, 2019
@Evangelink Evangelink added this to the CFG + Symbolic Execution milestone Mar 27, 2019
@andrei-epure-sonarsource andrei-epure-sonarsource modified the milestones: CFG + Symbolic Execution, 7.16 Jul 22, 2019
@AbbasNS AbbasNS self-assigned this Jul 22, 2019
@andrei-epure-sonarsource
Copy link
Contributor

fixed in #2497

@andrei-epure-sonarsource andrei-epure-sonarsource removed their assignment Jul 23, 2019
@andrei-epure-sonarsource andrei-epure-sonarsource changed the title BUG: S2683 reported incorrectly for Nullable<bool> ?? false Fix S2683 FP: reported incorrectly for Nullable<bool> ?? false Aug 12, 2019
@andrei-epure-sonarsource andrei-epure-sonarsource changed the title Fix S2683 FP: reported incorrectly for Nullable<bool> ?? false Fix S2683 FP: Nullable<bool> ?? false Aug 12, 2019
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 Positive Rule IS triggered when it shouldn't be.
Projects
None yet
Development

No branches or pull requests

4 participants