Skip to content
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

Missing hashCode definitions #706

Open
fpoli opened this issue May 26, 2023 · 0 comments
Open

Missing hashCode definitions #706

fpoli opened this issue May 26, 2023 · 0 comments

Comments

@fpoli
Copy link
Member

fpoli commented May 26, 2023

The Scalastyle linter complains about missing hashCode definitions in Silver. I'm not sure if we did that intentionally but it seems worth double-checking, adding a comment to Silver if there is nothing to fix.

Defining either equals() or hashCode() in a class without defining the other is a known source of bugs. Usually, when you define one, you should also define the other.

Further Reading: Scalastyle - EqualsHashCode

case class NodeEq(node: Rewritable) {
override def equals(that: Any): Boolean = that match {
case req: NodeEq => this.node eq req.node
case ref: AnyRef => this.node eq ref
case _ => false
}
}

trait StructuralEquality { self: AnyRef =>
protected val equalityDefiningMembers: Seq[Any]
override val hashCode = generateHashCode(equalityDefiningMembers)
override def equals(other: Any) = (
this.eq(other.asInstanceOf[AnyRef])
|| (other match {
case se: StructuralEquality if this.getClass.eq(se.getClass) =>
equalityDefiningMembers == se.equalityDefiningMembers
case _ => false
}))
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant