Skip to content

Incorrect usages of GetHashCode? #3116

@hmanner

Description

@hmanner

Considering the incorrect usage of GetHashCode in issue #2881, I decided to look through the code to see if there may be similar issues elsewhere. And I might have found a few.

I believe using GetHashCode() to determine equality is wrong, or at least bad practice. Two unequal objects may return the same hash code, depending on the GetHashCode() implementation.

This is from Indices.Equals:

		public override bool Equals(object obj)
		{
			var other = obj as Indices;
			if (other == null) return false;
			return this.Match(
				all => other.Match(a => true, m => false),
				many => other.Match(
					a => false,
					m => this.GetHashCode().Equals(other.GetHashCode())
				)
			);
		}

Similar code in:

Types.Equals
IndexName.EqualsMarker
RelationName.EqualsMarker
TypeName.EqualsMarker

Thoughts on this?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions