[C#] False positive on Nullable<bool> checks

17 views
Skip to first unread message

tamas...@gmail.com

unread,
Feb 7, 2017, 1:12:32 PM2/7/17
to SonarLint
Hello Guys,

The following code produces a false positive with S2583.

bool? x = null;

if (x == true)
{
}
else if (x == false) // S2583 reports false positive here
{
}

The problem is that we set a true or false constraint on SV_x when a constraint is set on x == true, however there's a third option that the x == true is false due to x being null, and == being the lifted operator.

Tamas

valeri....@sonarsource.com

unread,
Feb 8, 2017, 3:16:40 AM2/8/17
to SonarLint, tamas...@gmail.com
Hi Tamas,

Thanks for the bug report! We will gladly accept a PR with a fix.

I am kidding :)

I logged a bug in JIRA, we will fix it with the next update (you could review the PR if you want :).

All the best,
Valeri

Tamás Vajk

unread,
Feb 15, 2017, 2:08:28 PM2/15/17
to valeri....@sonarsource.com, SonarLint
Thanks Valeri. I see there're some changes in Jira (with many deprecated projects).
I think I'll leave this issue to you guys, it might not be as easy as it seems. 

When we put a true/false constraint on a comparison, we don't have the info if that operation was a lifted op or not. I'm not sure if this is required, but might be needed for more complex cases, such as:

bool? b = null;
if (!b == true)
{
...
}

Tamas

--
You received this message because you are subscribed to a topic in the Google Groups "SonarLint" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/sonarlint/xpUzlHvDcPk/unsubscribe.
To unsubscribe from this group and all its topics, send an email to sonarlint+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sonarlint/034bfa0f-ea57-4223-b2c5-0f7dd0fe080b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages