-
Notifications
You must be signed in to change notification settings - Fork 803
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
(=) uses non-generic equality on custom types #9398
Comments
Related: #526 |
This is kinda fixed by this PR, although it mightn't work 100% how you want it! In the above example, you would have to add a |
@manofstick, so this fix works correctly for records and unions, they are sealed, and for value types, they cannot be overridden. That raises the question that, by the time you fall through, you're either having a non sealed type that doesn't implement |
@abelbraaksma I think it would just make things more complex... I mean if you have an object hierarchy you probably shouldn't be using a specific IEquatable on a base type anyway... So marking a class that does have one as sealed probably isn't a terrible thing anyway... And boxing is never an issue for these, because this only affects reference types, so the call to equals is free (although obviously there is the cast back of the comparand, but this going to be at least as fast as a type check). Although it does do the other checks (am I IStructuralEquatable, am I an array, maybe that's it...), so possibly slight shaving of time there... |
@manofstick Oh yes, that makes sense, I didn't realize that a virtual call on I suddenly understand why the compiler always complains if I forget to do that. My mind goes like "why the extra work, you already have |
This is by design, the F# spec makes it clear that in the worst case |
Why would this be the worst case? The type implements |
The corresponding language suggestion is fsharp/fslang-suggestions#816 |
The current .Net advice is: If you implement IEquatable, you should also override ... Equals(Object).
The reason for this advice is: Non-Strongly typed collections and Frameworks don’t use IEquatable.
However now DE0006: Non-generic collections shouldn't be used.
So the expectation is that if you don't use .Net collections that predate generics, which you shouldn't do, then non-generic equality will not be used in preference to generic equality.
The text was updated successfully, but these errors were encountered: