Platform declaration clash

#1

Do you have any idea what a “synthetic inheritor” means? :slight_smile:
(I still try to extract some sample code that demonstrates the error.)

Platform declaration clash: The following declarations have the same JVM signature (remove(Ljava/lang/Object;)Ljava/lang/Object;):
    fun remove(key: K#1 (type parameter of p.X)): V#1 (type parameter of p.X)? defined in p.X
    fun remove(key: K#2 (type parameter of p.<synthetic inheritor of X>)): V#2 (type parameter of p.<synthetic inheritor of X>)? defined in p.<synthetic inheritor of X>
#2

The cause is that the compiler treats specially if core collection interfaces are used as a supertype: https://github.com/JetBrains/kotlin/blob/master/compiler/backend/src/org/jetbrains/kotlin/codegen/CollectionStubMethodGenerator.kt#L88
My class X indirectly implements kotlin.collections.Map and the compiler doesn’t seem to like it :frowning:

#3

Could you show the code of you class X?

#4

Here is an example code reproducing the same compile error:

interface SimpleMutableMap<K, V> : Map<K, V> {
     fun put(key: K, value: V): V?

     fun remove(key: K): V?
}

interface SomeInterface

class SimpleMutableHashMap<K, V: SomeInterface> : SimpleMutableMap<K, V> {
    override fun put(key: K, value: V): V? {
        TODO("not implemented")
    }

    override fun remove(key: K): V? {
        TODO("not implemented")
    }

    override val entries: Set<Entry<K, V>> get() = TODO("not implemented")

    override val keys: Set<K> get() = TODO("not implemented")

    override val size: Int get() = TODO("not implemented")

    override val values: Collection<V> get() = TODO("not implemented")

    override fun containsKey(key: K): Boolean {
        TODO("not implemented")
    }

    override fun containsValue(value: V): Boolean {
        TODO("not implemented")
    }

    override fun get(key: K): V? {
        TODO("not implemented")
    }

    override fun isEmpty(): Boolean {
        TODO("not implemented")
    }
}
#5

Thanks for the reproducer example. It looks like the following problem:
KT-22191 Unable to declare remove() method in interface that extends Collection due to collision with synthetic method

#6

Thanks for the info.