Kotlin / kotlinx.collections.immutable

Immutable persistent collections for Kotlin
Apache License 2.0
1.12k stars 56 forks source link

Implementation methods inherited from `kotlin-stdlib` `Abstract[x]` are not visible in interfaces #152

Closed Lordfirespeed closed 8 months ago

Lordfirespeed commented 9 months ago

For example, PersistentList. The interface declaration:

public interface ImmutableList<out E> : List<E>, ImmutableCollection<E> { /* ... */ }
public interface PersistentList<out E> : ImmutableList<E>, PersistentCollection<E> { /* ... */ }

reasonably claims it implements the List interface.

The base implementation declaration:

abstract class AbstractPersistentList<E> : PersistentList<E>, AbstractList<E>() { /* ... */ }

inherits stdlib's AbstractList, which contains methods not present in the List interface, such as

Which means that following the declaration of a PersistentList's hashCode function, for example, will go to Any#hashCode, which is misleading.

val myPersistentList: PersistentList<T> = persistentListOf(1,2,3)
myPersistentList.hashCode() // go to declaration -> `Any#hashCode`. Should be `AbstractList#hashCode`
Lordfirespeed commented 9 months ago

Truthfully, the same issue is apparent with stdlib builtins such as listOf, so perhaps this is more of a them problem. :joy:

qurbonzoda commented 8 months ago

Hi, Because PersistentList is an interface and does not provide hashCode implementation, navigating to the function leads to the Any.hashCode(). This is an expected behavior of the IntelliJ IDEA.