resharper breaks logic with invert If operation
I usually rely on Resharper for doing some simple code conversions/refactorings to reduce "human error", but recently I spotted a bug which seems to be related to one of the older issues: RSRP-186813
Basically resharper should treat things like:
nullableIntVal > 3
as
nullableIntVal.HasValue && nullableIntVal.Value > 3
BEFORE:
void Meth1(DateTime? date = null)
{
if (date < DateTime.MinValue)//Call invert if here
{
Console.Write("2");
return;
}
Console.Write("3");
}
run with no arguments: Meth1() - will output "3"
AFTER:
void Meth1(DateTime? date = null)
{
if (date >= DateTime.MinValue)
{
Console.Write("3");
}
else
{
Console.Write("2");
return;
}
}
run with no arguments: Meth1() - will output "2".
SHOULD BE?
Instead resharper should produce something like:
void Meth1(DateTime? date = null)
{
if (!date.HasValue || date >= DateTime.MinValue)
{
Console.Write("3");
}
else
{
Console.Write("2");
return;
}
}
Please sign in to leave a comment.
Hello Sergei
Thank you for reporting this problem! I've logged it as a separate issue: http://youtrack.jetbrains.net/issue/RSRP-288253.
Andrey Serebryansky
Senior Support Engineer
JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"