Unusual platform declaration clash


#1

The interfaces

interface IBack0 {

    val name : String

}

and

interface IBack1 {

    fun getName() : String

}

generate the same bytecode

public abstract interface {TypeName} {

      // access flags 0x401
      public abstract getName()Ljava/lang/String;
      @Lorg/jetbrains/annotations/NotNull;() // invisible
          LOCALVARIABLE this L{TypeName}; L0 L1 0

     //redacted kotlin metadata

}

However in utilization, only the interface using the field is faced with a platform declaration clash when paired with an abstract class

abstract class Back0 {

    fun getName() = ""

}

image

The error being


Class 'Inner0' is not abstract and does not implement abstract member public abstract val name: String defined in com.sxtanna.core.test.IBack0 Inherited platform declarations clash: The following declarations have the same JVM signature (getName()Ljava/lang/String;): fun <get-name>(): String defined in com.sxtanna.core.test.Inner0 fun getName(): String defined in com.sxtanna.core.test.Inner0

If you attempt to then implement the field from the interface, you are faced with this error

Is this normal behavior?


#2

From the Kotlin perspective a function and a property are a different thing. Both are incompatible, even though on Java the property when not private (and trivial) is generally implemented as a getter function. That is a platform specific detail, and as such you get a platform declaration clash.


#3

I understand why the clash occurs, but what I don’t understand why it has to occur.
The signature is satisfied with the property, and through Java, the usage would be exactly the same “getName()”. I am sure the compiler would be ok with you referring to it both by “getName()” and “name” since it already does this with Java code used in Kotlin.


#4

I would also like to see this implemented, it would make it more flexible.