Unfixed R# CodeGen bug might introduce subtle bugs in your code

Many of us use a nice code generation ability of Resharper to quickly implement IEquality<T> interface. Wonderful as it is, there is a very subtle bug R# creates in the generated code whenever it deals with double and float types.

The problem is due to the fact that double.NaN != double.NaN, while double.NaN.Equals(double.NaN) is true.
When R# generates bool Equals(T other), it makes the code "pretier" by replacing all _x.Equals(other._x) with  _x == other._x.  Even though this looks much easier to read, it WILL FAIL when _x is double, float, or any other user-defined type that may handle NaNs explicitly.

In short - any time you use your custom object with a double/float field as a key in a dictionary, and you set the field to NaN, dictionary will never find it!

The bug is critical because users generate code just once, and will NOT review it later after R# gets fixed!

The bug was filed as RSRP-104969 a long time ago, but still no fix

2 comments

Yuri Astrakhan wrote:

Many of us use a nice code generation ability of Resharper to quickly
implement IEquality<T> interface. Wonderful as it is, there is a very
subtle bug R# creates in the generated code whenever it deals with
double and float types.

The problem is due to the fact that double.NaN != double.NaN, while
double.NaN.Equals(double.NaN) is true. When R# generates *bool
Equals(T other)*, it makes the code "pretier" by replacing all
x.Equals(other.x) with  x == other.x.  Even though this looks
much easier to read, it WILL FAIL when _x is double, float, or any
other user-defined type that may handle NaNs explicitly.

In short - any time you use your custom object with a double/float
field as a key in a dictionary, and you set the field to NaN,
dictionary will never find it

*The bug is critical because users generate code just once, and will
NOT review it later after R# gets fixed!*

The bug was filed as http://www.jetbrains.net/jira/browse/RSRP-104969
a long time ago, but still no fix

---
Original message url:
http://www.jetbrains.net/devnet/message/5243652#5243652


#1 for that, i found this too, and was suprised when finding the error!

--

0

R# team has changed the priority to critical, yet still no fix

0

Please sign in to leave a comment.