Migration-Manager / binary compatibility: overriding hash-code with reference to private[this]

75 views Asked by At

Why is overriding hashCode a binary incompatible change:

Before:

trait Foo extends Product

After:

trait Foo extends Product {
  private[this] lazy val _hashCode = ScalaRunTime._hashCode(this)
  override def hashCode: Int = _hashCode
}

Migration-Manager says:

[error]  * synthetic method Foo$$_hashCode()Int in trait Foo is present only in current version
[error]    filter with: ProblemFilters.exclude[ReversedMissingMethodProblem]("Foo.Foo$$_hashCode")

Is this actually a problem? Or can I stay on the same minor version with this change?

1

There are 1 answers

0
0__ On BEST ANSWER

Not a direct answer, but it's possibly to avoid the private[this] lazy val altogether:

trait Foo extends Product {
  override lazy val hashCode: Int = ScalaRunTime._hashCode(this)
}

Here, MiMa does not complain.