Debug.Assert() to induce control flow

I frequently code things like this:

Debug.Assert(someObject != null, "Warning to developer!");
if (someObject != null)
{
DoSomething();
}

R# 2.5 adds a QuickFix to replace (someObject != null) with true because it assumes that the code doesn't reach this point with someObject == null because of the assertion. This simply is not true. As soon as this code is built in Release mode, code will actually reach this point. Using the QuickFix would significantly change the code's semantics.

I wouldn't like to completly deactivate the warning on trivial boolean expressions, though. I would consider this a bug.

1 comment
Comment actions Permalink

You can remove "Debug.Assert" methods from the list on "Value Analysis" option
page.

Valentin Kipiatkov
CTO and Chief Scientist
JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"

I frequently code things like this:

Debug.Assert(someObject != null, "Warning to developer!");
if (someObject != null)
{
DoSomething();
}
R# 2.5 adds a QuickFix to replace (someObject != null) with true
because it assumes that the code doesn't reach this point with
someObject == null because of the assertion. This simply is not true.
As soon as this code is built in Release mode, code will actually
reach this point. Using the QuickFix would significantly change the
code's semantics.

I wouldn't like to completly deactivate the warning on trivial boolean
expressions, though. I would consider this a bug.



0

Please sign in to leave a comment.