fixnum
fixnum copied to clipboard
Remove operator== considering Int64 == core.int
We have a work-around in place for the linter, but this seems not worth it at all:
- It makes comparisons brittle
(int640 == int0)
but (int0 != int640
). - It only seems useful for tests (and we could just create a custom
Matcher
) - It is confusing, I don't know of any other class that does this in the Dart ecosystem
/cc @davidmorgan
I think removing that is likely to break Intl's ability to format Int64. We rely on being able to ask things like someNumber.remainder(1) == 0
So let's just special case it? Seems silly here. We don't have the same treatment of BigInt
for example.
Special-casing it in Intl means adding a dependency on fixnum, which I'd prefer not to do.
Not doing this makes BigInt less useful. For example, you can't format it with Intl. At least BigInt we could special-case without adding a dependency because it's in the SDK.
Sounds reasonable still. This library is very lightweight and does not change much. It's a higher mental cost to have this behavior than worry about a dependency on fixnum.
By far the most common current use is to check whether an Int64
is equal to 0
. This does make the code look nicer, and people are using it.
Once the lint is updated, it will tell you if you do the comparison the wrong way around. At that point, there doesn't seem to be a lot of downside to the feature.
I wouldn't have designed it this way to start with, but I'm not sure it's worth a breaking change at this point.
This "feature" violates the == contract (https://api.dartlang.org/stable/2.0.0/dart-core/Object/operator_equals.html), since
void main() {
print(4 == Int64(4));
print(Int64(4) == 4);
}
prints
false true
so I think it's pretty clear it should be removed.
I agree. FWIW, I'd be willing to help with the migration internally if we make this change.
There is also the larger question of whether it is worth keeping Int64
now that we have BigInt
.