Skip to content

(=) uses non-generic equality on custom types #9398

@charlesroddie

Description

@charlesroddie
type T() =
    interface System.IEquatable<T> with member x.Equals _ = true
    override x.Equals _ = failwith "non-generic equality"
    override x.GetHashCode() = 0
T() = T() // System.Exception: non-generic equality

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions