Do not rely on descriptors in KParameterImpl.equals/hashCode

For the same reason as in the previous commit: descriptors are cached
via weak references in moduleByClassLoader.kt and can be
garbage-collected at any point. So different instances of KParameterImpl
representing the same parameter may store different instances of
descriptors.
This commit is contained in:
Alexander Udalov
2020-05-27 16:50:31 +02:00
parent 55f384cb04
commit 1f1790d60e
6 changed files with 68 additions and 2 deletions
@@ -64,10 +64,10 @@ internal class KParameterImpl(
get() = descriptor.let { it is ValueParameterDescriptor && it.varargElementType != null }
override fun equals(other: Any?) =
other is KParameterImpl && callable == other.callable && descriptor == other.descriptor
other is KParameterImpl && callable == other.callable && index == other.index
override fun hashCode() =
(callable.hashCode() * 31) + descriptor.hashCode()
(callable.hashCode() * 31) + index.hashCode()
override fun toString() =
ReflectionObjectRenderer.renderParameter(this)