-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Description
Following this PR: dotnet/corefx#10417
And these issues: https://github.com/dotnet/corefx/issues/10416, dotnet/corefx#10417
It seemed like support for == and != on ValueTuple might be needed. I don't know if the compiler already supports this ?
If not @gafter mentioned support for this should be in the compiler not in corefx.
I have two main concerns with adding operator== and operator!= to System.ValueTuple. Both of them boil down to the assertion that these operators should act as if operating using == on the underlying elements. But you can’t program that into the ValueTuple type, because the implementation of the generic type doesn’t know what operator== to apply to the elements. For example
- Using object.Equals(x, y) isn’t correct, because it isn’t the same as operator==. To take an example from our platform, double.NaN.Equals(double.Nan), but !(double.NaN==double.NaN). So (double.NaN == double.NaN) would give a different result from ((double.NaN, 0) == (double.NaN, 0)) if we implement the latter using object.Equals(); the former would be false while the latter would be true. I believe that is not what we want.
- We would want the == operator on tuples to apply whenever an underlying operator== can be found to apply on the elements, pointwise. If we do it in the language+compiler (now or in the future), we can make ((long)1, (byte)2) == ((short)1, (int)2) be true (not a compile-time error because no operator== can be found). However, there is no way to express that in source.
In short, I believe that adding support for operator== and operator!= to the sources of the ValueTuple libraries would be locking us in to the wrong semantics for what we would want the behavior to be.