Description
If you investigate the documentable model for a class with a companion object
, DClass.companion
and DClass.classlikes.single()
are different by reference. They represent the same object, and have the the same values in every field, recursively.
However, they are also different by value, because .equals()
on the data class DClass
recurses into DClass.sources.values.single().descriptor.equals()
, which is (in K1) a non-data-class org.jetbrains.kotlin.resolve.lazy.descriptors.LazyClassDescriptor
which compares by reference instead of by value. I would guess that the K2 implementation of DocumentableSource
similarly recurses into a problematic upstream object.
a) Please make sure that only one DObject
is created for each companion object. Not only should this (slightly) help performance, it will help avoid running into issues like this when trying to check if a companion object is contained within a list of objects.
b) Please make Documentable
s compare by value correctly. Avoiding sources
entirely in an overridden .equals()
/.hashCode
would maintain correctness IMO, but making the upstream objects inside all implementations of DocumentableSources
compare by value would probably be more correct, though skipping them in .equals()
/.hashCode
implementations probably can be made correct.