Search code examples
kotlinkotlin-multiplatform

Error: Declaration annotated with @OptionalExpectation can only be used in common module sources


Update (2018-11-03)

This is a known issue that is being tracked here.

Original Post

I am playing around with Kotlin MPP, specifically with Kotlin 1.3 and the new structure. After converting a Kotlin 1.2 MPP to the new structure, I keep getting these errors:

Error:(3, 18) Kotlin: [MPP_jvmMain] Declaration annotated with '@OptionalExpectation' can only be used in common module sources

These are referring to the @JsName() annotations I have within my common module.

I have tried:

  • Starting a completely new MPP from scratch using the built-in wizard, and simply adding @JsName("test") to the hello() function that comes with the generated sample. Even that seems to cause problems.
  • Invalidating caches/restarting IntelliJ
  • Using the latest versions of everything (Kotlin 1.3, IntelliJ IDEA 2018.2.5 Ultimate)
  • Calling ./gradlew build from the command line. This works.

Sample project here

Link Kotlin Issue


Solution

  • This was fixed within v1.3.10 of the Kotlin plugin for IntelliJ.