Search code examples
kotlinkotlin-js-interopkotlin-multiplatform

Different semantics of KProperty1<T, R> in JS compared to JVM


It looks like KProperty1<T, R> has different semantics in JVM and JS e.g. while this test works on the JVM:

data class Data(val name: String)
class Test {
    @Test fun propertiesMustBeEqual() {
        assertEquals(Data::name, Data::name)
    }
}

it fails in Javascript with this message:

1) test
       Test
         propertiesMustBeEqual:
     AssertionError: Expected <function ($receiver) {
      return $receiver.name;
    }>, actual <function ($receiver) {
      return $receiver.name;
    }>

Any ideas how to solve this?


Solution

  • Unbound property references to the same property should be equal on all platforms. But the situation that they aren't equal in JS is a bug tracked as https://youtrack.jetbrains.com/issue/KT-15101