-
Notifications
You must be signed in to change notification settings - Fork 22
Outer check should use equals rather than eq in inner class #11940
Copy link
Copy link
Closed
Description
reproduction steps
// class Wrapper, inner class Foo
class Wrapper {
// all Wrapper instances are "equals"
override def equals(obj: Any) =
obj != null && obj.isInstanceOf[Wrapper]
case class Foo()
}
// create two Foo instances via two Wrapper instances
val wrapper1 = new Wrapper
val foo1 = new wrapper1.Foo()
val wrapper2 = new Wrapper
val foo2 = new wrapper2.Foo()
// get a hand on the outer reference of Foo
val outerFld = classOf[Wrapper#Foo].getDeclaredField("$outer")
outerFld.setAccessible(true)
// equality checks
val outerReferencesEqual = outerFld.get(foo1) == outerFld.get(foo2)
val instancesEqual = foo1 == foo2problem
instancesEqual is false, even though outerReferencesEqual is true.
expectation
instancesEqual is true.
This is related to but not exactly the same problem as #4440 (comment). Here, we don't have the final modifier, so we don't run in #4440. The issue here is about the use of eq, rather than equals, to compare outer references.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels